3

我有一个表,每行都有一个隐藏字段。单击该行中的按钮时,我需要提醒隐藏字段的值。我有以下 jQuery 代码。但它不起作用。我们如何让它发挥作用?

代码:http: //jsfiddle.net/Lijo/xWanB/

<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>
4

4 回答 4

18

您的选择器以tr:first > .wrapperDivHidden ....wrapperDivHidden不是直接子级开头,tr因此请更改您的选择器,如下所示:

$(this).parents('tr').find('.wrapperDivHidden input[type="hidden"]').val();

小提琴:http: //jsfiddle.net/xWanB/3/

于 2012-05-30T13:14:59.313 回答
2

试试这个:

<script type="text/javascript">

    $(document).ready(function () {
        //"Show ID" for Associate Button Click
        $('.actionButtonNational').click(function () {
            var associateID = $('input[type=hidden]', $(this).closest("td")).val();
            alert(associateID);
            return false;
        });
    });
</script>
于 2012-05-30T13:18:59.073 回答
0

这是您尝试执行的操作的过度简化示例:

http://jsfiddle.net/6S5rD/

于 2012-05-30T13:25:32.523 回答
0

如果您的行的第一列被隐藏然后使用这个 var x = $('input[type=hidden]', $(this).find("td:first")).val();

于 2014-12-01T17:46:45.773 回答