【问题标题】:How to get the hidden field value in each table row如何获取每个表格行中的隐藏字段值
【发布时间】:2017-11-07 17:40:34
【问题描述】:

我只想获取表格每一行的隐藏字段值,如何 我可以这样做吗,任何建议表示赞赏

【问题讨论】:

    标签: jquery hidden-field


    【解决方案1】:

    这是一个使用数组的简单示例。您只想获取隐藏的输入值并将其推送到数组中。

    //create hidden fields array
    var hiddenFields = [];
    
    //for each table row
    $("#yourTable tr").each(function()
    {
      //get hidden field value
      var hiddenField = $(this).find("input[type='hidden']").val();
      
      //if not empty push to array
      if(hiddenField !='undefined'&& hiddenField !=null )
        hiddenFields.push(hiddenField);
    });
    
    //output all hidden field values stored in array
    console.log(hiddenFields);
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <table id="yourTable">
      <tr><th>row id</th><th>column 1</th><th>column 2</th></tr>
      <tr>
        <td><input type="hidden" value="row id 1"> 1
    </td><td>row 1</td><td>row 1</td>
      </tr>
      <tr>
        <td><input type="hidden" value="row id 2"> 2
    </td><td>row 2</td><td>row 2</td>
      </tr>
      <tr>
        <td><input type="hidden" value="row id 3"> 3
    </td><td>row 3</td><td>row 3</td>
      </tr>
    </table>

    【讨论】:

    • 感谢 yoda,我通过查看您的回答找到了一种方法。!
    【解决方案2】:
    function ApplyProcessingColor()
        {
            $("#xhtml_grid tr").each(function()
            {
                var hdnLock=$(this).find("td:first").text();
                if(hdnLock=='True')
                {
                    $(this).css('background-Color','#7FFFD4');
                }
            });
        }
    

    这样我找到了解决办法

    【讨论】:

      猜你喜欢
      • 2012-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-20
      相关资源
      最近更新 更多