[英]not able to disable select tag
有一个li,在该列表内有一个复选框(主复选框)和另一个ul,该ul包含一个复选框列表(子复选框)并选择标签(子选择)。 我希望当我取消选中主要检查时,所有子复选框均应取消选中,并且select标记也应被禁用和重置。 我取消选中子复选框的第一部分工作正常,但无法禁用和搁置选择框。 这是我的jQuery
$('.mainCb').on('change', function () {
if ($(this).is(':checked')) {
$(this).parent().find('.subUl').show();
} else {
$(this).parent().find('.subUl').hide();
$(this).parent().find('.subUl input:checkbox').prop('checked', false);
$(this).parent().find('.subUl input:select').attr('disabled', true); // for disabling select but not able to disable select
}
});
用这个,
$(this).parent().find('.subUl select').prop('disabled', true);
input:select
是错误的选择器。
.
subUl
选择器中缺少- $(this).parent().find('subUl select')
。
var parent = $(this).parent();
使用this(caching)而不是每次都调用它。
$('.mainCb').on('change', function () {
var parent = $(this).parent();
if ($(this).is(':checked')) {
parent.find('.subUl').show();
} else {
parent.find('.subUl').hide();
parent.find('.subUl input:checkbox').prop('checked', false);
parent.find('.subUl select').prop('disabled', true); // for disabling select but not able to disable select
}
});
您缺少“。” 在最后一个语句的css选择器中。 还将“ attr”更改为“ prop”。
$('.mainCb').on('change', function () {
if ($(this).is(':checked')) {
$(this).parent().find('.subUl').show();
} else {
$(this).parent().find('.subUl').hide();
$(this).parent().find('.subUl input:checkbox').prop('checked', false);
$(this).parent().find('.subUl select').prop('disabled', true); // for disabling select but not able to disable select
}
});
最后声明应该是
$(this).parent().find('.subUl input:select').attr('disabled', true);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.