我想阻止同等價值的多種選擇,但值=「他人」只能多選防止相同值的多重選擇,但允許值可以在多個
我的代碼是這樣的
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) {
if(select.selectedIndex !== "Others"){
if(select.selectedIndex != "") {
alert('You\'ve already selected the item "' + select.options[index].text + '".\n\nPlease choose another.');
}
this.selectedIndex = 0;
}
} else if(index === "other") {
}
}
var f61 = select = document.getElementById('f61');
var f62 = select = document.getElementById('f62');
var f63 = select = document.getElementById('f63');
f61.onchange = function() {
preventDupes.call(this, f62, this.selectedIndex);
preventDupes.call(this, f63, this.selectedIndex);
};
f62.onchange = function() {
preventDupes.call(this, f61, this.selectedIndex);
preventDupes.call(this, f63, this.selectedIndex);
};
f63.onchange = function() {
preventDupes.call(this, f62, this.selectedIndex);
preventDupes.call(this, f61, this.selectedIndex);
};
<select name="indication_subject[]" id="f61">
<option value="" selected="selected">Subject </option>
<option value="Accounting"> Accounting</option>
<option value="Afrikaans"> Afrikaans</option>
<option value="Arabic"> Arabic</option>
<option value="other">Others</option>
</select>
<select name="indication_subject[]" id="f61">
<option value="" selected="selected">Subject </option>
<option value="Accounting"> Accounting</option>
<option value="Afrikaans"> Afrikaans</option>
<option value="Arabic"> Arabic</option>
<option value="other">Others</option>
</select>
<select name="indication_subject[]" id="f63">
<option value="" selected="selected">Subject </option>
<option value="Accounting"> Accounting</option>
<option value="Afrikaans"> Afrikaans</option>
<option value="Arabic"> Arabic</option>
<option value="other">Others</option>
</select>
對此有何想法?
此代碼無法在IE 7上運行 – wyman 2011-03-08 13:32:46