使用引导开关切换禁用输入框

jashuang1130

我尝试使用自举开关按钮切换时禁用/启用表中的输入框。

<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:这只会禁用第一个

 $(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);
      }
 });
罗宾·麦肯齐

您可以使用它来切换输入disabled属性some_value

$('#constraint_checkbox').on('change', function(event, state) {
  var status = $('#some_value').prop('disabled');
  $('#some_value').prop('disabled', !status);
});

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章