Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
201 views
in Technique[技术] by (71.8m points)

javascript - jQuery to get Hidden Field Value in Table Row

I have a table with a hidden field in each row. I need to Alert the value of hidden field when a button in that row is clicked. I have the following jQuery code. But it does not work. How do we make it work?

CODE: 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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

your selector starts with tr:first > .wrapperDivHidden ... but .wrapperDivHidden is not an immediate child of tr so change your selector like so:

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

Fiddle: http://jsfiddle.net/xWanB/3/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...