1
我的代码:jQuery的HTML内容
// Get message
var PostTxt = $('#cid367', '.comment-txt').html();
PostTxt = $.trim(PostTxt);
它正在尝试从这种结构的评论:
<div id="cid367" class="comment-wrapper">
<div class="comment-head ch-highlight">
<div class="comment-date">
<abbr class="timeago" title="2011-04-25T15:15:52.4070000">25 April 2011 at 15:15:52</abbr>
</div>
<div class="comment-author">
Written by <a id="A1" title="Visit this game makers profile" href="../../../users/Tom">Tom</a>
</div>
</div>
<table class="comment-body" width="100%">
<tr>
<td width="100" valign="top" align="center">
<a id="A2" title="Tom makes games with Construct 2" href="../../../users/Tom"><img id="Img1" title="Tom's Gravatar" class="comment-avatar" src="http://www.gravatar.com/avatar/5271d3283db957ef3a86761ed15c1696?r=pg&s=80" /></a>
</td>
<td valign="top">
<div id="ModBox" class="comment-modbox" style="margin-left:-105px;">
<a id="CommentReportPost" title="Report this post" class="s comment-report"></a>
<a id="CommentDeletePost" title="Delete this post" class="s comment-delete" onclick="DeleteComment('367');return false;" href="JavaScript:void(0)"></a>
<a id="CommentEditPost" title="Edit this post" class="s comment-edit" onclick="EditComment('367');return false;" href="JavaScript:void(0)"></a>
<a id="CommentQuotePost" title="Quote this post" class="s comment-quote" href="JavaScript:void(0)"></a>
</div>
<div class="comment-txt">
My comment text to get
</div>
</td>
</tr>
</table>
<div class="clear"></div>
</div>
但它一直返回null。任何人都可以告诉我这是怎么完成的?
尝试在不使用trim()的情况下看到结果。听起来很愚蠢,但有时候会有帮助。 – 2011-04-25 15:22:57