jQuery在表行中获取隐藏字段值 [英] jQuery to get Hidden Field Value in Table Row

查看:567
本文介绍了jQuery在表行中获取隐藏字段值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在每一行都有一个隐藏字段的表。我需要提醒隐藏字段的值,当该行中的一个按钮被点击。我有以下jQuery代码。但它不工作。我们如何使它工作?



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

 < script> 
$(document).ready(function(){

//关联按钮的显示ID单击
$('。resultGridTable tr> td> .actionButtonNational ').click(function(){
//this表示显示ID按钮
//遍历获取父行,然后获取行中所需的列
var associateID = $ (this).parents('tr:first> .wrapperDivHidden input [type = hidden]')。val();
alert(associateID);
return false;
}
});
< / script>



HTML

 < td> 
XXXXX
< input type =submitname =ctl00 $ detailContentPlaceholder $ grdSubscribedAssociates $ ctl04 $ btnNational
value =Show IDid =detailContentPlaceholder_grdSubscribedAssociates_btnNational_2
=actionButtonNationalstyle =color:White; background-color:#A7A7A6;
font-weight:bold; width:60px/>
< div id =wrapperDivHiddenclass =wrapperDivHidden>
< input type =hiddenname =ctl00 $ detailContentPlaceholder $ grdSubscribedAssociates $ ctl04 $ hdnAssociateID
id =detailContentPlaceholder_grdSubscribedAssociates_hdnAssociateID_2value =789345680/>
< / div>
< / td>


解决方案

您的选择器以 tr :first> .wrapperDivHidden ... .wrapperDivHidden 不是 tr 的直接子您的选择器如下:

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

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


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>

解决方案

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/

这篇关于jQuery在表行中获取隐藏字段值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆