日期:2014-05-16  浏览次数:20447 次

求助:下拉列表的问题??
现在需要做到的是:有一个下拉列表(2个选项),其下面有2个输入框(但同一时间只能有一个显示)

选项1对应输入框1,也就是说当选择的是1是下面显示输入框1,输入框2是隐藏的。

这是用js做的东西还是用Ajax?

如果js能做到,各位大哥能提供以下js的代码吗?

------解决方案--------------------
HTML code

<script>
function show(n){
document.getElementById("a1").style.display="none";
document.getElementById("a2").style.display="none";

document.getElementById("a"+n).style.display="";
}
</script>
<select onchange="show(this.options[this.selectedIndex].value)">
<option value="1">1</option>
<option value="2">2</option>
</select>
<input id="a1" value="a1">
<input id="a2" value="a2" style="display:none;">

------解决方案--------------------
<html>
<body>
<script language="javascript" type="text/javascript">
function excu(obj)
{
if(obj==0)
{
document.getElementById("text1").style.display = "block";
document.getElementById("text2").style.display = "none";
}
else
{
document.getElementById("text2").style.display = "block";
document.getElementById("text1").style.display = "none";
}
}
</script>
<select name="sel" onchange="excu(this.options[this.selectedIndex].value);">
<option value="0">0</option>
<option value="1">1</option>
</select>
<br />
<input type="text" id="text1" value="txt0"/>
<input type="text" id="text2" value="txt1"/>
</body>



</html>
------解决方案--------------------
JScript code

window.onload=function()
{
   $("txt1").style.display=$("txt2").style.display='none';
}

function change(obj)
{
   if(obj.options[0].selected)
   {
      $("txt1").style.display='';
      $("txt2").style.display='none';
   }
   else
   {
      $("txt1").style.display='none';
      $("txt2").style.display='';
   }
}

function $(objID)
{
   return document.getElementById(objID);
}