为什么有些网站(或提供客户端javascript代码的广告客户)采用了在通话中拆分<script>和/或</script>标记的技术document.write()?
我注意到亚马逊也这样做了,例如:
<script type='text/javascript'>
if (typeof window['jQuery'] == 'undefined') document.write('<scr'+'ipt type="text/javascript" src="http://z-ecx.images-amazon.com/images/G/01/javascripts/lib/jquery/jquery-1.2.6.pack._V265113567_.js"></sc'+'ript>');
</script>
Run Code Online (Sandbox Code Playgroud) 究竟需要在javascript字符串中进行转义.或者,更具体地说,为什么
var snaphtml = '<script src="http://seadragon.com/embed/lxe.js?width=auto&height=400px"></script>';
Run Code Online (Sandbox Code Playgroud)
给出语法错误?逃避决赛<\/script>似乎修复了语法错误,但这对我作为javascript初学者没有意义.
我为什么要......
SyntaxError:未终止的字符串文字
...在Firefox和...
未捕获的SyntaxError:无效或意外的令牌
... 当我跑...时在Chrome中 ...
$(document).ready(function () {
function addJSBeforeEndBody(code) {
$('body').append('<script>' + code + '</script>');
}
addJSBeforeEndBody('$(document).ready(function() { console.log("I never end up here."); });');
});Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>Run Code Online (Sandbox Code Playgroud)
请查看我的代码.
var id = 1;
var htmlText = '<div id="horizontalUserPopup"><ul id="tabs1" class="rtabs"></ul><div class="panel-container"><div id="view1"><script>viewMiniProfile("'+id+'",this);</script></div><div id="view2"></div><div id="view3" style="display:none;">Blah Blah Blah</div><div id="view4" style="display:none;">444444</div></div></div>';
$('#contents').html(htmlText);
Run Code Online (Sandbox Code Playgroud)
以上代码我得到以下错误 -

如果我删除</script>其工作罚款.请检查并让我知道.
编辑:
完整代码 -
function modelInfo(id, username) {
var pageUrl = $('#pageurl').val();
$('#model-popup-box1 h3').addClass('newsfeed');
var content_area = $('#model-popup-content1');
content_area.html('Please wait...');
$('#model-popup-box-title1').html('About ' + username);
$('#model-popup-body1').show();
content_area.html('<div id="horizontalUserPopup"><ul id="tabs1" class="rtabs"></ul><div class="panel-container"><div id="view1"><script>viewMiniProfile("'+id+'",this);</script></div><div id="view2"></div><div id="view3" style="display:none;">Blah Blah Blah</div><div id="view4" style="display:none;">444444</div></div></div>');
var innerHtml = "<li><a href=\"#view1\" id='miniprofile-view1' onclick=\"viewMiniProfile('"+id+"',this)\">Mini-Profile</a></li>" +
"<li><a href=\"#view2\">Tokens</a></li>" +
"<li><a href=\"#view3\">Notes</a></li><li><a href=\"#view4\">PM Logs</a></li>";
var …Run Code Online (Sandbox Code Playgroud)