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

为什么执行JS后,原有的下拉列表框就没有了?
我想要实现的功能是在下拉列表框的值变化时,动态生成一个TABLE,TABLE内容为下拉列表框的值,但为什么我下拉列表框值变化后,就只显示了值,而下拉列表框没有了.
--------------------------------------------
<body>
...
<select   name= "state3 "   style= "width:   300px; "   onChange= "javascript:setVal(state3.value) ">
        <option   value= "AL "> Alabama </option>
        <option   value= "AK "> Alaska </option>
        <option   value= "AS "> American   Samoa </option>
        <option   value= "AZ "> Arizona </option>
    </select>
<script   language= "javascript ">
  function   setVal(sel)
  {  
     
    str= " <table   bgcolor= 'yellow '> <tr> <td> "+sel+ " </td> </tr> </table> ";
    //document.write( "get ");
      document.write(str);    
  }
</script>
...
</body>


------解决方案--------------------
<html>
<head>
</head>
<body>
<select name= "state3 " style= "width: 300px; " onChange= "javascript:setVal(state3.value) ">
<option value= "AL "> Alabama </option>
<option value= "AK "> Alaska </option>
<option value= "AS "> American Samoa </option>
<option value= "AZ "> Arizona </option>
</select>
<script language= "javascript ">
function setVal(sel)
{

str= " <table bgcolor= 'yellow '> <tr> <td> "+sel+ " </td> </tr> </table> ";

document.getElementById( "divId ").innerHTML = str;
}
</script>
<div id= "divId "> </div>
</body>
</html>