<html> 
<head> 
<script type="text/javascript"> 
function getOptions() 
  { 
  var x=document.getElementById("mySelect");
  for (i=0;i <x.options.length;i++) 
    { 
document.getElementById("ospan").innerHTML += x.options[i].text+"<br/>"
    } 
  } 
</script> 
</head> 
<body> <form> 
Select your favorite fruit: 
<select id="mySelect">          
  <option>Apple </option> 
  <option>Orange </option> 
  <option>Pineapple </option> 
  <option>Banana </option> 
</select> 
<br /> <br /> 
<input type="button" onclick="getOptions()" 
value="Output all options"> 
<span id='ospan'></span>
</form> </body> 
</html>
自己看下document.write用法 会重写文档

解决方案 »

  1.   

    var x=document.getElementById("mySelect");//这里传值的时候,是怎么传的????? 
    这只是取 select 对象document.write(x.options[i].text)    //这里应该是把select中的全部都输出来吧,那为什么运行后就输出选中的 
    要全输出来,  你得取出  OPTION 属性对象 来输
      

  2.   

    不要用document.write
    用alert吧因为它会抹去页面的内容
      

  3.   

    document.write会将你自己的页面内容重写
      

  4.   

    2楼的大哥,你的代码没问题,我想问一下<span> 标签被用来组合文档中的内联元素,什么叫内联元素,你为什么要用那个?
      

  5.   

    document.write会将你自己的页面内容重写