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

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

问题描述

我有一个表与各行隐备案。我要提醒的是排在单击按钮时隐藏的提交的值。我有以下的jQuery code。但是,这是行不通的。我们如何使它工作?

code: http://jsfiddle.net/Lijo/xWanB/

 <脚本类型=文/ JavaScript的>    $(文件)。就绪(函数(){        //显示ID为副按钮点击
        $('resultGridTable TR方式> TD> .actionButtonNational')点击(函数(){。            //这指显示ID按钮
            //遍历获取父行,然后需要的列行中
            VAR associateID = $(本)。家长('TR:第一> .wrapperDivHidden输入[类型=隐藏]')。VAL();
            警报(associateID);
            返回false;
        });
    });
< / SCRIPT>

HTML

 < TD>
                    XXXXX
                    <输入类型=提交名称=$ ctl00 $ detailContentPlaceholder $ grdSubscirbedAssociates $ ctl04 btnNational
                        值=显示IDID =detailContentPlaceholder_grdSubscirbedAssociates_btnNational_2
                        类=actionButtonNational的风格=颜色:白色,背景色:#A7A7A6;
                        字体重量:大胆的;宽度:60像素/>
                    < D​​IV ID =wrapperDivHidden级=wrapperDivHidden>
                        <输入类型=隐藏的名字=$ ctl00 $ detailContentPlaceholder $ grdSubscirbedAssociates $ ctl04 hdnAssociateID
                            ID =detailContentPlaceholder_grdSubscirbedAssociates_hdnAssociateID_2VALUE =789345680/>
                    < / DIV>
    < / TD>


解决方案

您选择使用 TR开始:第一个> .wrapperDivHidden ... ,但 .wrapperDivHidden 不是的直接子 TR 这样的变化你选择像这样:

  $(本)。家长('TR')找到('wrapperDivHidden输入[类型=隐藏。)VAL()。

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

I have a table with a hidden filed in each row. I need to Alert the value of hidden filed 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 type="text/javascript">

    $(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$grdSubscirbedAssociates$ctl04$btnNational"
                        value="Show ID" id="detailContentPlaceholder_grdSubscirbedAssociates_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$grdSubscirbedAssociates$ctl04$hdnAssociateID"
                            id="detailContentPlaceholder_grdSubscirbedAssociates_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天全站免登陆