我正在尝试在链接的点击事件中获取隐藏字段的值。这是这些元素所在的位置:
<p>
<a class="showCommentAttachment cboxElement" href="#">Attachments</a>
<input type="hidden" value="13" id="ctl00_ContentPlaceHolder1_lvComment_ctrl3_hfCommentId" name="ctl00$ContentPlaceHolder1$lvComment$ctrl3$hfCommentId">
</p>
以下是完整的标记:
<div id="divComment" class="comment-text">
<div class="comment-author">
David Chart
</div>
<span class="comment-date-time">Sep 29, 2011 08:12:42 PM</span>
<p>
Some comment text goes here. Some comment text goes here.
</p>
<p>
<a class="showCommentAttachment cboxElement" href="#">Attachments</a>
<input type="hidden" value="13" id="ctl00_ContentPlaceHolder1_lvComment_ctrl3_hfCommentId" name="ctl00$ContentPlaceHolder1$lvComment$ctrl3$hfCommentId">
</p>
</div>
以下是 jQuery 代码:
$("#divComment a.showCommentAttachment").click(function() {
var nextSibling = $(this).next().find('input:hidden').val();
$("#showCommentId").html(nextSibling + "<-- Here's the comment ID ");
});
我从nextSibling得到的是未定义的。我试过使用nexAll,像这样:
var nextSibling = $(this).nextAll().find('input:hidden').val();
仍然得到了未定义。
谢谢。