这是错误:
Uncaught SyntaxError: Unexpected token ILLEGAL
d.d.extend.globalEvaljquery-1.5.1.min.js:16
d.ajaxSetup.converters.text scriptjquery-1.5.1.min.js:16
bQjquery-1.5.1.min.js:16
vjquery-1.5.1.min.js:16
d.support.ajax.d.ajaxTransport.send.c
这是jQuery:
$("div#notif_js").html(' ');
$("div#notification_box").html('<div class="notification">
<p><img alt="Justin meltzer" class="feed_image_notif" src="/system/photos/46/tiny/Justin Meltzer.jpeg?1303109121" /> JMeltz
added a comment to <b>second</b> by <img alt="Justin meltzer" class="feed_image_notif" src="/system/photos/45/tiny/Justin Meltzer.jpeg?1303109101" /> Justin Meltzer</p>
<a href="/videos/506"></a>
</div>
<div class="notification">
<p><img alt="Justin meltzer" class="feed_image_notif" src="/system/photos/46/tiny/Justin Meltzer.jpeg?1303109121" /> JMeltz
added a comment to <b>second</b> by <img alt="Justin meltzer" class="feed_image_notif" src="/system/photos/45/tiny/Justin Meltzer.jpeg?1303109101" /> Justin Meltzer</p>
<a href="/videos/506"></a>
</div>
<div class="notification">
<p><img alt="Justin meltzer" class="feed_image_notif" src="/system/photos/46/tiny/Justin Meltzer.jpeg?1303109121" /> JMeltz
added a comment to <b>second</b> by <img alt="Justin meltzer" class="feed_image_notif" src="/system/photos/45/tiny/Justin Meltzer.jpeg?1303109101" /> Justin Meltzer</p>
<a href="/videos/506"></a>
</div>
<div class="notification">
<p><img alt="Justin meltzer" class="feed_image_notif" src="/system/photos/46/tiny/Justin Meltzer.jpeg?1303109121" /> JMeltz upvoted bhbu </p>
<a href="/videos/505"></a>
</div>
<div class="notification">
<p class= "all_notifications">All Notifications</p>
<a href="/videos/notification_go"></a>
</div>');
答案 0 :(得分:1)
Javascript不允许您在字符串中包含多行。您需要将每一行转换为\ n,如下所示:
$("div#notification_box").html('line1\nline2');
或在每行结尾之前加上'\',如下所示:
$("div#notification_box").html('line1\
line2');
第一种方法似乎更常用,但我认为第二种方法看起来更好。
另外,检查javascript错误的一种简单方法是通过javascript delinter运行它,例如http://www.javascriptlint.com/online_lint.php或http://www.jslint.com/(尽管jslint不会像javascriptline那样报告错误)
答案 1 :(得分:0)