【问题标题】:Setting attributes for the first column's contents with jquery使用 jquery 设置第一列内容的属性
【发布时间】:2014-04-23 03:15:35
【问题描述】:

我有下表动态加载到<div>

现在我正在尝试遍历表以禁用标题为“索引”的第一列中的所有输入字段。我该怎么办?

我想出的是以下,但它失败了:

$('#output').find('tr').each().find('td').first().find('input').attr('disabled','disabled');

【问题讨论】:

    标签: jquery traversal tree-traversal dom-traversal jquery-traversing


    【解决方案1】:

    这应该也可以。

    $('#output tr td:first-child input').attr('disabled', 'disabled');
    

    一个选择器中的所有内容。仅在 chrome 中测试

    http://jsfiddle.net/QGdJF/

    【讨论】:

      【解决方案2】:
      $('table tr td:nth-child(1) input').prop('disabled',true)
      

      jsFiddle example

      由于您没有发布表格的 HTML,我提供了一个通用示例。根据您的确切代码,您可以将选择器替换为 $('#output td:nth-child(1) input')

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多