1 回答

TA贡献1807条经验 获得超9个赞
我认为您不能在菜单列表上添加事件监听器,但必须为每个菜单完成
var menus = document.querySelectorAll('.otherMenu');
for (let menu of menus) {
menu.addEventListener('change', function () {
var selectedOption = this.value;
var selectWife = document.querySelectorAll('.otherMenu option[value="Wife"]');
var selectHusband = document.querySelectorAll('.otherMenu option[value="Husband"]');
selectWife.forEach(function (option) {
option.disabled = selectedOption === 'Wife';
});
selectHusband.forEach(function (option) {
option.disabled = selectedOption === 'Husband';
});
});
}
添加回答
举报