gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-27 23:20:58 25 4
gpt4 key购买 nike

当我使用引导开关按钮切换时,我试图禁用/启用表格中的输入框。

<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);
}
});

最佳答案

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

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

关于jquery - 使用引导开关切换禁用输入框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41111200/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com