[求助]下拉菜单和文本框的联动,问题出在哪里呢?
下面代码,不加<form>时没有问题,加<form>后就会出现'this.SelTest.selectedIndex' 为空或不是对象的错误,请问是哪错了?应该怎样改?<html>
<head>
</head>
<script language="javascript" >
function SelTest_Change()
{
var SelIdx=this.SelTest.selectedIndex;
var selOpt=this.SelTest.options[SelIdx];
switch(selOpt.value)
{
case "A":
this.ShowText.style.display="none";
break;
case "B":
this.ShowText.style.display="inline";
break;
}
}
</script>
<body>
<form name="form1" method="post" action="1.asp"><!--去掉这一行和</form>就不会报错-->
<select name="SelTest" onChange="SelTest_Change();" >
<option selected >请选择</option>
<option value="A">A</option>
<option value="B">B</option>
</select>
<div id="ShowText" style="display:none" ><input type="text" name="TxtTest" ></div>
</form>
</body>
</html>
<head>
</head>
<script language="javascript" >
function SelTest_Change()
{
var SelIdx=this.SelTest.selectedIndex;
var selOpt=this.SelTest.options[SelIdx];
switch(selOpt.value)
{
case "A":
this.ShowText.style.display="none";
break;
case "B":
this.ShowText.style.display="inline";
break;
}
}
</script>
<body>
<form name="form1" method="post" action="1.asp"><!--去掉这一行和</form>就不会报错-->
<select name="SelTest" onChange="SelTest_Change();" >
<option selected >请选择</option>
<option value="A">A</option>
<option value="B">B</option>
</select>
<div id="ShowText" style="display:none" ><input type="text" name="TxtTest" ></div>
</form>
</body>
</html>