当复选框选中时,我正在尝试启用和禁用文本框。但此处只有一个文本框在选中复选框时启用。如何在选中复选框时启用和禁用两个文本框?下面是我的代码:
<script src="plugins/jQuery/jquery-2.2.3.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('.input_control').change(function () {
$('input[name=' + this.value + ']')[0].disabled = !this.checked;
}).change();
});
</script>提前感谢..!!
发布于 2016-08-05 20:58:35
[0]将只返回单个DOM元素,因此它只适用于单个元素。
因为需要修改多个元素的值,所以应该使用.prop( propertyName, value )方法
为匹配的元素集设置一个或多个属性。
$('input[name=' + this.value + ']').prop("disabled", !this.checked);发布于 2016-08-05 20:58:51
$('input[name=' + this.value + ']')[0].prop( "disabled", !this.checked);编辑:
$('input[name=' + this.value + ']').first().prop( "disabled", !this.checked);
$('input[name=' + this.value + ']').prop( "disabled", !this.checked);https://stackoverflow.com/questions/38789803
复制相似问题