var pagepath = window.location.pathname;
$.ajax({
type: 'post',
url: '{{ url_for("getposts") }}',
data: {'category':pagepath},
success: function (msg) {
$.each(msg, function (i, n) {
var row = $('#post-clone').clone();
var postid = n.id;
console.log(postid);
row.find('#post-name').text(n.name);
row.find('#post-author').text(n.author);
row.find('#post-ctime').text(n.ctime);
row.find('#post-mtime').text(n.mtime);
row.find('#post-small').text(n.small);
row.find('#postcontainer_p').text(n.container);
if ( n.author == '{{ g.user.username }}') {
$('a#post-getpost').attr('onclick', 'getpost(n.id)');
}
row.appendTo('#post-content').css('display', 'block')
})
}
});javascript if判断执行体中无法使用变量
问题在于getpost(n.id),会报错.提示n未定义.
数据使用json传递到jquery.
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
'getpost('+n.id+')'这样?