通过 Jquery 调用 tr 属性并找到我的内部复选框

Calling the tr attribute via Jquery and find my inner check box

本文关键字:我的 内部 复选框 Jquery 调用 tr 属性 通过      更新时间:2023-09-26

我有属性"data-uid"的"tr"元素。如何在我的 jquery 中调用该"data-uid"以查找我的复选框以添加禁用的类。

这是我的代码:

<tr data-uid="994f164a-5778-49ee-b05e-abb74bbf9b93" role="row">
   <td role="gridcell"><label class="row-select-wrapper">
      <input type="checkbox" class="row-select"><em></em></label>
   </td>
   <td role="gridcell">test</td>
   <td role="gridcell"></td>
   <td role="gridcell"></td>
</tr>

我尝试过这样的事情

$('data-uid[994f164a-5778-49ee-b05e-abb74bbf9b93]')
.find('<input type="checkbox"').attr("disabled", "true");

在使用属性选择器时,您实际上也需要将您使用的属性选择器类型括起来:

$('[data-uid="994f164a-5778-49ee-b05e-abb74bbf9b93"]').find('<input type="checkbox"')
                                                      .attr("disabled", "true");

此外,如果您想通过使用:checkbox伪选择器来定位<tr>下方的复选框,则可以简化选择器:

// This will disable all checkboxes beneath the specified row
$('[data-uid="994f164a-5778-49ee-b05e-abb74bbf9b93"] :checkbox').prop('disabled',true);

你很接近:

 $('[data-uid=994f164a-5778-49ee-b05e-abb74bbf9b93]')
          .find('input[type=checkbox]').attr("disabled", "true");