【发布时间】:2016-09-22 12:56:49
【问题描述】:
$.ajax({
url:'/getArticles',
method:'GET',
}).done(function(articles){
var content = '';
articles.forEach(function(e){
var res = "<div class='article'>" +
"<h3>" + e.title + "</h3>" +
"<p>" + e.content + "</p><br>" +
"<button onclick=crud.remove(" + e._id + ")>Remove</button><br>" +
"</div>";
content += res;
});
$('#allarticles').append(content);
});
window.crud = (function(){
// Remove an article
function remove(id){
console.log(id);
}
如何在此处正确插入e._id,以便将文章 id 放入?
当我点击这个按钮时,它会说:
(index):1 Uncaught SyntaxError: Invalid or unexpected token
【问题讨论】:
-
将参数放在引号中:
"<button onclick=\"crud.remove('" + e._id + '")\">Remove</button><br>"
标签: javascript jquery