我有三个组合框:
每个组合框都有以下值可供选择:
Combobox 1:
Combobox 2:
Combobox 3:
当在Combobox 1中选择值时,假设为英语,则在Combobox 2&amp ;;中禁用该值。 3两者。我想在javascript中这样做。可以任何身体帮助。我想禁用此值而不删除它。
提前致谢。
修改
我试过了:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
function selectedLanguage(lang,comboxbox_id){
console.log(comboxbox_id);
var langSelected = lang.options[lang.selectedIndex].value;
console.log(langSelected);
if(comboxbox_id === 'language1'){
if(langSelected === 1){
//do nothing
document.getElementById('language2').style.disabled = true;
}else if(langSelected === 2){
}
}else if(comboxbox_id === 'language2'){
if(langSelected === 1){
//do nothing
}else if(langSelected === 2){
}
}
}
</script>
</head>
<body>
<select name="language1" id="language1" onchange="selectedLanguage(this,this.id)">
<option value="1">French</option>
<option value="2">English US</option>
<option value="3">Greek</option>
<option value="4">Swedish</option>
</select>
<select name="language2" id="language2" onchange="selectedLanguage(this,this.id)">
<option value="1">French</option>
<option value="2">English US</option>
<option value="3">Greek</option>
<option value="4">Swedish</option>
</select>
</body>
</html>
答案 0 :(得分:0)
这样的事情?
$(document).on('change', '.combobox', function() {
var $otherComboOptions = $('.combobox').not($(this)).find('option'),
value = this.value;
$otherComboOptions.each(function() {
if (value === this.value) {
this.disabled = true;
} else {
this.disabled = false;
}
});
});