我有此hbs代码:
<table>
<tr>
<th>A</th>
<th>B</th>
</tr>
{{#each data2}}
<tr>
<td>
<input
type='checkbox'
id='nm_produk'
class='product'
name='data_{{no}}'
value="{{no}}">
<label>{{item}}</label>
</td>
<td>
<input
disabled type='text'
placeholder='0'
name='data_{{no}}'
id='qtytbs'>
</td>
</tr>
{{/each}}
</table>
和此脚本:
$(document).ready(function() {
$(".product").change(function() {
$next = $(this).closest('tr').find('[id=qtytb]');
$next.prop('disabled', !this.checked);
});
});
当我选中复选框时,输入元素的同一行被启用,我们可以在上面写上文字。但是当我取消选中该复选框时,该值仍然存在最后一个值。当我取消选中复选框元素时,我想在同一行的输入元素上获取空白值并禁用它。
我该如何实现?
添加$ next.val('');仅在禁用复选框的情况下将其设置为代码。您可能需要编写一个if条件来设置空值。
将您的JS代码更改为: