どのようにテーブルのチェックボックスを設定するには、チェックされていますか?

Imrik:

私は私が持っているテーブル持ってidチェックするように私は、設定したいというチェックボックスのを、私はそれを行うことができないと私は理由を知りません。

私はこれをしようとしたが、何も起こりませんし、私は、エラーメッセージのいずれかの種類を持っていません。

$('#medicalListTable input.type_checkbox[id="sindicate-345"]').prop('checked', true);
$('input.type_checkbox[id="sindicate-345"]').prop('checked', true);
$('input.type_checkbox[id="sindicate-345"]').attr('checked', true);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table id="medicalListTable" class="display responsive nowrap dataTable no-footer" cellspacing="0" width="100%" role="grid" aria-describedby="medicalListTable_info" style="width: 100%;">
  <thead>
    <tr role="row">
      <th class="sorting ui-state-default sorting_asc" tabindex="0" aria-controls="medicalListTable" rowspan="1" colspan="1" aria-sort="ascending" aria-label="Id empleado: activate to sort column descending" style="width: 134px;">
        <div class="DataTables_sort_wrapper">Id empleado<span class="DataTables_sort_icon css_right ui-icon ui-icon-triangle-1-n"></span></div>
      </th>
      <th class="sorting ui-state-default" tabindex="0" aria-controls="medicalListTable" rowspan="1" colspan="1" aria-label="Nombre: activate to sort column ascending" style="width: 174px;">
        <div class="DataTables_sort_wrapper">Nombre<span class="DataTables_sort_icon css_right ui-icon ui-icon-caret-2-n-s"></span></div>
      </th>
      <th class="sorting ui-state-default" tabindex="0" aria-controls="medicalListTable" rowspan="1" colspan="1" aria-label="Apellidos: activate to sort column ascending" style="width: 329px;">
        <div class="DataTables_sort_wrapper">Apellidos<span class="DataTables_sort_icon css_right ui-icon ui-icon-caret-2-n-s"></span></div>
      </th>
      <th class="sorting ui-state-default" tabindex="0" aria-controls="medicalListTable" rowspan="1" colspan="1" aria-label="Seleccionar: activate to sort column ascending" style="width: 125px;">
        <div class="DataTables_sort_wrapper">Seleccionar<span class="DataTables_sort_icon css_right ui-icon ui-icon-caret-2-n-s"></span></div>
      </th>
    </tr>
  </thead>
  <tbody>
    <tr role="row" class="odd">
      <td class="vehicleId sorting_1">345</td>
      <td class="model">NAME</td>
      <td class="model">SURNAME</td>
      <td>
        <input type="checkbox" id="sindicate-345">
      </td>
    </tr>
  </tbody>
</table>

ロリーMcCrossan:

何もありませんtype_checkbox要素のクラスが。私はあなたの代わりにこのような属性セレクタを使用するためのものと推定します。

$('#medicalListTable input[type="checkbox"][id="sindicate-345"]').prop('checked', true);

しかし、あなたが持っている場合idそれはあなたが使用する必要が唯一の選択であるように、要素の上には、DOMで一意である必要があります。

$('#sindicate-345').prop('checked', true);

$('#sindicate-345').prop('checked', true);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table id="medicalListTable" class="display responsive nowrap dataTable no-footer" cellspacing="0" width="100%" role="grid" aria-describedby="medicalListTable_info" style="width: 100%;">
  <thead>
    <tr role="row">
      <th class="sorting ui-state-default sorting_asc" tabindex="0" aria-controls="medicalListTable" rowspan="1" colspan="1" aria-sort="ascending" aria-label="Id empleado: activate to sort column descending" style="width: 134px;">
        <div class="DataTables_sort_wrapper">Id empleado<span class="DataTables_sort_icon css_right ui-icon ui-icon-triangle-1-n"></span></div>
      </th>
      <th class="sorting ui-state-default" tabindex="0" aria-controls="medicalListTable" rowspan="1" colspan="1" aria-label="Nombre: activate to sort column ascending" style="width: 174px;">
        <div class="DataTables_sort_wrapper">Nombre<span class="DataTables_sort_icon css_right ui-icon ui-icon-caret-2-n-s"></span></div>
      </th>
      <th class="sorting ui-state-default" tabindex="0" aria-controls="medicalListTable" rowspan="1" colspan="1" aria-label="Apellidos: activate to sort column ascending" style="width: 329px;">
        <div class="DataTables_sort_wrapper">Apellidos<span class="DataTables_sort_icon css_right ui-icon ui-icon-caret-2-n-s"></span></div>
      </th>
      <th class="sorting ui-state-default" tabindex="0" aria-controls="medicalListTable" rowspan="1" colspan="1" aria-label="Seleccionar: activate to sort column ascending" style="width: 125px;">
        <div class="DataTables_sort_wrapper">Seleccionar<span class="DataTables_sort_icon css_right ui-icon ui-icon-caret-2-n-s"></span></div>
      </th>
    </tr>
  </thead>
  <tbody>
    <tr role="row" class="odd">
      <td class="vehicleId sorting_1">345</td>
      <td class="model">NAME</td>
      <td class="model">SURNAME</td>
      <td>
        <input type="checkbox" id="sindicate-345">
      </td>
    </tr>
  </tbody>
</table>

おすすめ

転載: http://10.200.1.11:23101/article/api/json?id=7513&siteId=1