我有一张表格,每行都有一个隐藏字段。单击该行中的按钮时,我需要提醒隐藏字段的值。我有以下jQuery代码。但这行不通。我们如何使其工作?
<script> $(document).ready(function () { //"Show ID" for Associate Button Click $('.resultGridTable tr > td > .actionButtonNational').click(function () { //"this" means show ID button //Traversing to get the parent row and then the required columns in the row var associateID = $(this).parents('tr:first > .wrapperDivHidden input[type=hidden]').val(); alert(associateID); return false; }); }); </script>
HTML
<td> XXXXX <input type="submit" name="ctl00$detailContentPlaceholder$grdSubscribedAssociates$ctl04$btnNational" value="Show ID" id="detailContentPlaceholder_grdSubscribedAssociates_btnNational_2" class="actionButtonNational" style="color: White; background-color: #A7A7A6; font-weight: bold; width: 60px" /> <div id="wrapperDivHidden" class="wrapperDivHidden"> <input type="hidden" name="ctl00$detailContentPlaceholder$grdSubscribedAssociates$ctl04$hdnAssociateID" id="detailContentPlaceholder_grdSubscribedAssociates_hdnAssociateID_2"value="789345680" /> </div> </td>
您的选择器以开头,tr:first >.wrapperDivHidden...但.wrapperDivHidden不是的直接子项,tr因此请按以下方式更改选择器:
tr:first >.wrapperDivHidden...
.wrapperDivHidden
tr
$(this).parents('tr').find('.wrapperDivHidden input[type="hidden"]').val();