js问题selectedIndex是空值
<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN""http://www.w3.org/TR/html4/l...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head>
<script type="text/javascript">
arrCity=new Array();
arrCity[0]=["黑A","黑B","黑C"];
arrCity[1]=["吉A","吉B","吉C","吉D"];
arrCity[2]=["贵A","贵B","贵C","贵D"];
arrCity[3]=["辽A","辽B","辽C","辽D","辽E"];
function a_change(){
index=document.getElementById("a").selectedIndex;
document.getElementById("b").options.length=0;//执行后数组参照为0使其不让其出现累加的效果
for(i=0;i<arrCity[index].length;i++){
var option=document.createElement("option");
option.value=arrCity[index][i];
option.text=arrCity[index][i];
document.getElementById("b").add(option);
}
}
function a_init()//出现的效果是第一次执行时有数值
{
a_change();
}
</script>
<body onload="a_init()">
<select name="a" onchange="a_change()">
<option value="黑龙江">黑龙江</option>
<option value="吉林">吉林</option>
<option value="贵州">贵州</option>
<option value="辽宁">辽宁</option>
</select>
<select name="b">
</select>
</body>
</html>
在运行时说selectedIndex是空值怎么回事,我在body已经有事件执行过了,怎么还会出现这问题 展开
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head>
<script type="text/javascript">
arrCity=new Array();
arrCity[0]=["黑A","黑B","黑C"];
arrCity[1]=["吉A","吉B","吉C","吉D"];
arrCity[2]=["贵A","贵B","贵C","贵D"];
arrCity[3]=["辽A","辽B","辽C","辽D","辽E"];
function a_change(){
index=document.getElementById("a").selectedIndex;
document.getElementById("b").options.length=0;//执行后数组参照为0使其不让其出现累加的效果
for(i=0;i<arrCity[index].length;i++){
var option=document.createElement("option");
option.value=arrCity[index][i];
option.text=arrCity[index][i];
document.getElementById("b").add(option);
}
}
function a_init()//出现的效果是第一次执行时有数值
{
a_change();
}
</script>
<body onload="a_init()">
<select name="a" onchange="a_change()">
<option value="黑龙江">黑龙江</option>
<option value="吉林">吉林</option>
<option value="贵州">贵州</option>
<option value="辽宁">辽宁</option>
</select>
<select name="b">
</select>
</body>
</html>
在运行时说selectedIndex是空值怎么回事,我在body已经有事件执行过了,怎么还会出现这问题 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询