回 帖 发 新 帖 刷新版面

主题:请教高手下拉框的JavaScript问题,谢谢~

请教高手下拉框的JavaScript问题,谢谢~  有1系列不同类型的测试题目,要求
拉框选可选项ABCD,在下拉框选中B和C时,旁边的输入框disabled(不是不显示)
例如:选类型A/D时,可以输入,<input type=text name=QQ size=4 maxlength=4>
     选类型B/C时,禁止输入,<input disabled type=text name=QQ size=4 maxlength=4>
该怎么写啊?

测试代码---

<html>

<script language=JavaScript type=text/javascript>
function chg()
{
 var d=document.f1;
 if (d.selectq.value == 0) 
     ...???
 else if (d.selectq.value == 1)
     ...???
 else if (d.selectq.value == 2)
     ...???
 d.submit();
}
</script>

<body>
<form name=f1 method=POST>
<table width=438 height=110><font size=3 color=#0099CC><b>
  <td width=430 height=106>选择题</b><br><br><br>
  <select name=selectq onchange=chg()>
  <option value=0 selected>类型A &nbsp;
  <option value=1>类型B &nbsp;
  <option value=2>类型C &nbsp;
  <option value=3>类型D &nbsp;
  </select>

  问题<input type=text name=QQ size=4 maxlength=4> 

</table> 
<input type=submit name=submit value=提交> 
</form>  </body> </html>

回复列表 (共2个回复)

沙发

<html>

<script language=JavaScript>
function chg()
{
 for(i=0;i<4;i++)
 {
 if(this.f1.q[i].selected==true)
 {
  if(i==2||i==1)
  f1.QQ.disabled=true;
  else
  f1.QQ.disabled=false;
 }
}
}
</script>

<body>
<form name=f1 method=POST>
<table width=438 height=110><font size=3 color=#0099CC><b>
  <td width=430 height=106>选择题</b><br><br><br>
  <select name=q onchange="javascript:chg();">
  <option value="1">类型A &nbsp;</option>
  <option value="2">类型B &nbsp;</option>
  <option value="3">类型C &nbsp;</option>
  <option value="4">类型D &nbsp;</option>
  </select>

  问题<input type=text name=QQ size=10 maxlength=10> 

</table> 
<input type=submit name=submit value=提交> 
</form>  </body> </html>

板凳

问题解决,非常感谢 wangsdong!

我来回复

您尚未登录,请登录后再回复。点此登录或注册