我试图用这一行调用一个函数 find(\'' + news_text + '\') 但它给了我
SyntaxError:未终止的字符串文字
字符串可能如下所示:“Barnes & Noble to launch video service for 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>');
}
}
}