尝试使用此行调用函数find(\''+ news_text +'\')但它给了我
SyntaxError:unterminated string literal
字符串可能如下所示:“Barnes& Noble为Nook \ r http://t.co/NTnycGYD启动视频服务”
以下是解决问题的代码:
function show(news_user, news_date, news_profile_img, news_text, news_url, user_tweets) {
$('#news-tweets')
.css({
'overflow-y': 'scroll',
'overflow-x': 'hidden'
});
$('#news-tweets')
.append('<div class="tweets"><div class="user">' + news_user + '</div><div class="date">' + news_date + '</div>\
<span class="clear">\
</span><div class="img"><a href="' + news_profile_img + '" target="_blank"><img src="' + news_profile_img + '" width="55" height="50"/>\
</a></div>\
<div class="text">' + news_title + '<br /><a onclick="find(\'' + news_text + '\')">Show user tweets..</a></div></div>');
}
function find(news_text) {
$('#user-news-tweets')
.html("");
for (var x = 0; x < user_tweets.length; x++) {
var user = user_tweets[x].user;
var date = user_tweets[x].date;
var profile_img = user_tweets[x].user_profile_img;
var url = user_tweets[x].url;
var text = user_tweets[x].text;
var text3 = text.replace(/\r"\/:\.`'/g, "");
if (text3.indexOf(news_text.substr(0, 10)) > -1) {
$('#user-news-tweets')
.css({
'overflow-y': 'scroll',
'overflow-x': 'hidden'
});
$('#user-news-tweets')
.append('<div class="tweets"><div class="user">' + user + '</div><div class="date">' + date + '</div>\
<span class="clear"></span><div class="img"><a href="' + profile_img + '" target="_blank">\
<img src="' + profile_img + '" width="55" height="50"/></a></div>\
<div class="text">' + text + '<br /></div>');
}
}
}
答案 0 :(得分:3)
尝试终止字符串,就像错误所说的那样。
find('\' + news_text + '\')
答案 1 :(得分:0)
尝试以下操作(您还错过了div
标记以关闭div.tweets
开始)。尽管它看起来不那么优雅,但我总是更喜欢这种逃避撇号的元素。我已经包含了回车以便于删除它们。
$("#news-tweets").append("
<div class=\"tweets\">
<div class=\"user\">" + news_user + "</div>
<div class=\"date\">" + news_date + "</div>
<span class=\"clear\"></span>
<div class=\"img\">
<a href=\"" + news_profile_img + "\" target=\"_blank\">
<img src=\"" + news_profile_img + "\" width=\"55\" height=\"50\" />
</a>
</div>
<div class=\"text\">" + news_text + "<br />
<a onclick=\"find(\"" + news_text + "\");\">Show user tweets..</a>
</div>
</div>
");