2

ブートストラップ スイッチ ボタンで切り替えるときに、テーブル内の入力ボックスを無効/有効にしようとしています。

<table class="table .table-striped">
  <thead>
    <tr>
      <th>Number</th>
      <th>Inputbox</th>
      <th>checkbox</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td> 1 </td>
      <td><input id="some_value" type="number" class="form-control input-md" value=""></td>
      <td><input data-size="small" type="checkbox" id="constraint_checkbox" ></td>
    </tr>
    <tr>
      <td> 2 </td>
      <td><input id="some_value" type="number" class="form-control input-md" value=""></td>
      <td><input data-size="small" type="checkbox" id="constraint_checkbox" ></td>
    </tr>
    <tr>
      <td> 3 </td>
      <td><input id="some_value" type="number" class="form-control input-md" value=""></td>
      <td><input data-size="small" type="checkbox" id="constraint_checkbox" ></td>
    </tr>
  </tbody>
</table>

-- jQuery の方法 1: これはまったく機能しません。

$('#constraint_checkbox').on('switchChange', function(event, state) {
    $(this).prop('enable', true);
  })

-- 方法 2 : これは最初の 1 つだけを無効にします

 $(selector).on('switchChange.bootstrapSwitch', function(event, state) {
     if ($(selector).is(':checked') == false){
       $('#some_value').val('').prop('disabled', true);
      }
     else {
       $('#some_value').val('').prop('disabled', false);
      }
 });
4

1 に答える 1