<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;">

解决方案 »

  1.   

    <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>
      

  2.   


    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);
    }
    <select id="sel" onchange="change(this)">
    <option>option-1</option>
    <option>option-2</option>
    </select>
    <div>
    <input type="text" id="txt1" value="1">
    <input type="text" id="txt2" value="2">
    </div>========================================
    思路都差不多.
      

  3.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
     <HEAD>
      <TITLE> New Document </TITLE>
      <META NAME="Generator" CONTENT="EditPlus">
      <META NAME="Author" CONTENT="">
      <META NAME="Keywords" CONTENT="">
      <META NAME="Description" CONTENT="">
    <script>
    function show()
    {
    var select = event.srcElement;
    //alert(select.options.length);
    for(var i = 0 ;i<select.options.length;i++)
    {
    if(select.options[i].selected)
    {
    if(select.options[i].value=="1")
    {
    var first = document.getElementById("1");
    var second = document.getElementById("2");
    first.style.display = "block";
    second.style.display = "none";
    }
    else if(select.options[i].value=="2")
    {
    var first = document.getElementById("1");
    var second = document.getElementById("2");
    first.style.display = "none";
    second.style.display = "block";
    }
    else
    {
    var first = document.getElementById("1");
    var second = document.getElementById("2");
    first.style.display = "none";
    second.style.display = "none";
    }
    }
    }
    }
    </script> </HEAD> <BODY>
      <select onchange="show();">
      <option value="0">0</option>
    <option value="1">1</option>
    <option value="2">2</option>
      </select>  <input style="display:none" value="1" type="text" id="1">
    <input style="display:none" value="2" type="text" id="2">
     </BODY>
    </HTML>