0
下面是一些代码:jQuery的获得innter文本
jQuery.each(comments, function(i, comment)
{
cl.append("<div class='comment_entry' id='" + comment.id + "' style='background-color: " + colors[color] + ";'><div class='ce_time'>" + comment.time + "</div><div class='ce_poster'>" + comment.poster_name + "</div><div class='ce_comment' id='ce_comment'>" + comment.comment + "</div></div>");
color = 1 - color;
});
jQuery(".comment_entry").click(function()
{
//alert(this.ce_comment);
alert(jQuery('this').find('#ce_comment').text());
});
什么,我这里做的是在飞行中添加的DIV。然后,我正在为他们的课程添加点击事件给DIV。点击DIV时,应该在DIV ID'ce_comment'中显示文本。相反,我得到一个空白。我知道DIV中有文字,因为我可以在页面上看到它。
那么,在这种情况下访问文本的正确方法是什么?
只能有一个元素的id为'ce_comment',可能应该使用'ce_comment'类来访问点击注释中的文本。 – antejan