0
function preventDupes(select, index) {
var options = select.options,
len = options.length;
while(len--) {
options[ len ].disabled = false;
}
select.options[ index ].disabled = true;
if(index === select.selectedIndex) {
alert('You\'ve already selected the item "' + select.options[index].text + '".\n\nPlease choose another.');
this.selectedIndex = 0;
}
}
var select1 = select = document.getElementById('select1');
var select2 = select = document.getElementById('select2');
var select3 = select = document.getElementById('select3');
var select4 = select = document.getElementById('select4');
var select5 = select = document.getElementById('select5');
select1.onchange = function() {
preventDupes.call(this, select2, this.selectedIndex);
preventDupes.call(this, select3, this.selectedIndex);
preventDupes.call(this, select4, this.selectedIndex);
preventDupes.call(this, select5, this.selectedIndex);
};
select2.onchange = function() {
preventDupes.call(this, select1, this.selectedIndex);
preventDupes.call(this, select3, this.selectedIndex);
preventDupes.call(this, select4, this.selectedIndex);
preventDupes.call(this, select5, this.selectedIndex);
};
select3.onchange = function() {
preventDupes.call(this, select1, this.selectedIndex);
preventDupes.call(this, select2, this.selectedIndex);
preventDupes.call(this, select4, this.selectedIndex);
preventDupes.call(this, select5, this.selectedIndex);
};
select4.onchange = function() {
preventDupes.call(this, select1, this.selectedIndex);
preventDupes.call(this, select2, this.selectedIndex);
preventDupes.call(this, select3, this.selectedIndex);
preventDupes.call(this, select5, this.selectedIndex);
};
select5.onchange = function() {
preventDupes.call(this, select1, this.selectedIndex);
preventDupes.call(this, select2, this.selectedIndex);
preventDupes.call(this, select3, this.selectedIndex);
preventDupes.call(this, select4, this.selectedIndex);
};
我試圖禁用已經選擇的下拉字段,但是它禁用了最後選擇的下拉值。我想要的是什麼;如何在使用Javascript禁用下列下拉菜單中選擇值
當用戶第一次選擇會計時,應該在其他4個下拉列表中禁用該選項。然後如果用戶選擇生物學,則生物學和會計必須在其他3個下拉列表中禁用。因此,用戶可以設置前五個選項