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