两个select 需要用第一个select的onchange事件来决定第二个的option 求解
1个回答
展开全部
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
aaa:<select id="selectObj1" onchange="changeMe(this)">
<option value="1">111</option>
<option value="2">222</option>
</select>
bbb:<select id="selectObj2">
<option value="21">1-1-b</option>
</select>
</BODY>
</HTML>
<SCRIPT LANGUAGE="JavaScript">
<!--
function changeMe(obj){
var obj2 = document.getElementById("selectObj2"); //获取第二个select对象
obj2.remove(0); //删除子节点
var oOption = document.createElement("OPTION"); //创建新option
obj2.options.add(oOption); //将新option添加到select对象
if(obj.value=="1"){
oOption.innerText = "change1111"; //设置option内容和value
oOption.value = "21";
}else{
oOption.innerText = "change222";
oOption.value = "22";
}
}
//-->
</SCRIPT>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
aaa:<select id="selectObj1" onchange="changeMe(this)">
<option value="1">111</option>
<option value="2">222</option>
</select>
bbb:<select id="selectObj2">
<option value="21">1-1-b</option>
</select>
</BODY>
</HTML>
<SCRIPT LANGUAGE="JavaScript">
<!--
function changeMe(obj){
var obj2 = document.getElementById("selectObj2"); //获取第二个select对象
obj2.remove(0); //删除子节点
var oOption = document.createElement("OPTION"); //创建新option
obj2.options.add(oOption); //将新option添加到select对象
if(obj.value=="1"){
oOption.innerText = "change1111"; //设置option内容和value
oOption.value = "21";
}else{
oOption.innerText = "change222";
oOption.value = "22";
}
}
//-->
</SCRIPT>
追问
我想问如果是关于数据库的读取而不是自定义的呢 有什么好的方法么?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询