< script></script> JavaScript代码中的标签? [英] <script></script> tags inside of javascript code?
问题描述
I'm using a plugin that I found from searching the web called Apprise. It has worked well for what I have needed thus far. But, I want to apprise the facebook login plugin and to to that I need to following code:
<fb:login-button scope='email,publish_stream'>
Login
</fb:login-button>
<script type='text/javascript' src='http://connect.facebook.net/en_US/all.js'></script>
<script>
window.fbAsyncInit = function() {
FB.init({
appId: '123456789',
cookie: true,
xfbml: true,
oauth: true
});
FB.Event.subscribe('auth.login', function(response) {
window.location = '/fb_redirect.php';
});
FB.Event.subscribe('auth.logout', function(response) {
window.location.reload();
});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
任何想要被告知的事情都可以通过放置
Anything that you want to be apprised can be done by putting
apprise();
在javascript中.但是,将<script></script>
标记放在JS代码(apprise();
)内会引起各种混乱,因为尚不清楚JS代码在何处结束.
in the javascript. However, putting the <script></script>
tags inside of the JS code (apprise();
) causes all sorts of confusion because it's not clear where the JS code ends.
有什么想法吗?
推荐答案
在<script>
块和内联Javascript中均可使用的方法是\uxxxx
,其中xxxx
是十六进制字符代码.
The method that works in both <script>
blocks and inline Javascript is \uxxxx
, where xxxx
is the hexadecimal character code.
-
<
-\u003c
-
>
-\u003e
-
"
-\u0022
-
'
-\u0027
-
\
-\u005c
-
&
-\u0026
<
-\u003c
>
-\u003e
"
-\u0022
'
-\u0027
\
-\u005c
&
-\u0026
演示:
HTML:
<div onClick="alert('Hello \u0022>')">click me</div>
<script>
var s = 'Hello \u003c/script\u003e';
</script>
这篇关于< script></script> JavaScript代码中的标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!