【问题标题】:jQuery to get Hidden Field Value in Table RowjQuery获取表行中的隐藏字段值
【发布时间】:2012-06-04 17:35:17
【问题描述】:

我有一个表,每行都有一个隐藏字段。单击该行中的按钮时,我需要提醒隐藏字段的值。我有以下 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>

【问题讨论】:

    标签: javascript jquery asp.net html css


    【解决方案1】:

    您的选择器以 tr:first &gt; .wrapperDivHidden ... 开头,但 .wrapperDivHidden 不是 tr 的直接子代,因此请更改您的选择器:

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

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

    【讨论】:

      【解决方案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>
      

      【讨论】:

        【解决方案3】:

        这是您尝试做的一个过度简化的示例:

        http://jsfiddle.net/6S5rD/

        【讨论】:

        • 我正在使用 ASP.Net HiddenField。因此它可能对我有用。
        【解决方案4】:

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

        【讨论】:

          猜你喜欢
          • 2011-03-12
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-03-06
          • 2013-12-30
          • 2013-09-12
          • 1970-01-01
          相关资源
          最近更新 更多