开发者

How to Iterate Over JavaScript Object and Display results In Specified Place?

I have object replies:

[Object { content="Comment #1."}, Object { content="Comment #2."}]  

And I have selector that selects place where content should be placed...

$('.post .comment_this[rel="3"]').parent().parent开发者_JAVA技巧().append(encoded.content + '<br />');

How to iterate over that object and display results in that place one by one?


replies is an array, you can use a simple for loop:

var $target = $('.post .comment_this[rel="3"]').parent().parent();

for(var i = 0, l = replies.length; i < l; i++) {
    $target.append(replies[i].content + '<br />');
}


http://api.jquery.com/each/

Assuming

var replies = [{ content:"Comment #1."}, { content:"Comment #2."}];

you can use something like this DEMO HERE

var target = $('.post .comment_this[rel="3"]').parent().parent();
$.each(replies, function(i, reply) { target.append("<br/>"+reply.content)});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜