Jquery 无法禁用选择标记
列表中有一个li,我有一个复选框(主复选框)和另一个ul,ul包含一个复选框列表(子复选框)和选择标签(子选择)。我希望当我取消选中主复选框时,所有子复选框都应该取消选中,并且选择标签应该被禁用和重置。 我取消选中子复选框的第一部分工作正常,但无法禁用和停止选择框。 这是我的jqueryJquery 无法禁用选择标记,jquery,html,checkbox,Jquery,Html,Checkbox,列表中有一个li,我有一个复选框(主复选框)和另一个ul,ul包含一个复选框列表(子复选框)和选择标签(子选择)。我希望当我取消选中主复选框时,所有子复选框都应该取消选中,并且选择标签应该被禁用和重置。 我取消选中子复选框的第一部分工作正常,但无法禁用和停止选择框。 这是我的jquery $('.mainCb').on('change', function () { if ($(this).is(':checked')) { $(this).pare
$('.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
}
});
您在上一条语句的css选择器中缺少。。同时将“属性”更改为“属性”
$('.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);
用这个,
$(this).parent().find('.subUl select').prop('disabled', true);
是错误的选择器input:select
在
选择器-subUl
$(this).parent()中缺失。查找('subUl select')
var parent=$(this.parent()代码>使用这个(缓存),而不是每次调用它
$('.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
}
});