求教 js控制3个select的options选项动态添加删除
要求是這樣的,select A,B,C各有3個選項a,b,c,A選了第一個選項a後,B,C就不能選a,B選了b後,A,C就不能選擇b,B選了c的話,A,C就不能選擇c,求js代碼...
<select id="aaa" onchange="filter()">
<option value=""></option>
<option value="0">a</option>
<option value="1">b</option>
<option value="2">c</option>
</select>
<select id="bbb" onchange="filter()">
<option value=""></option>
<option value="0">a</option>
<option value="1">b</option>
<option value="2">c</option>
</select>
<select id="ccc" onchange="filter()">
<option value=""></option>
<option value="0">a</option>
<option value="1">b</option>
<option value="2">c</option>
</select>
<script>
var a = document.getElementById("aaa");
var b = document.getElementById("bbb");
var c = document.getElementById("ccc");
function filter()
{
b.innerHTML = "";
c.innerHTML = "";
if (a.value == 0)
{
var option = document.createElement("option");
option.value = 1;
option.innerHTML = "b";
b.appendChild(option);
var option = document.createElement("option");
option.value = 2;
option.innerHTML = "c";
b.appendChild(option);
var option2 = document.createElement("option");
option2.value = 1;
option2.innerHTML = "b";
c.appendChild(option2);
var option2 = document.createElement("option");
option2.value = 2;
option2.innerHTML = "c";
c.appendChild(option2);
}
else if (a.value==1){
var option = document.createElement("option");
option.value = 0;
option.innerHTML = "a";
b.appendChild(option);
var option = document.createElement("option");
option.value = 2;
option.innerHTML = "c";
b.appendChild(option);
var option2 = document.createElement("option");
option2.value = 0;
option2.innerHTML = "a";
c.appendChild(option2);
var option2 = document.createElement("option");
option2.value = 2;
option2.innerHTML = "c";
c.appendChild(option2);
} else {
var option = document.createElement("option");
option.value = 0;
option.innerHTML = "a";
b.appendChild(option);
var option = document.createElement("option");
option.value = 1;
option.innerHTML = "b";
b.appendChild(option);
var option2 = document.createElement("option");
option2.value = 0;
option2.innerHTML = "a";
c.appendChild(option2);
var option2 = document.createElement("option");
option2.value = 1;
option2.innerHTML = "b";
c.appendChild(option2);
}
}
</script>
------解决方案--------------------<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html