当前位置: 代码迷 >> JavaScript >> 改正下小弟我的异常代码 ,多谢
  详细解决方案

改正下小弟我的异常代码 ,多谢

热度:24   发布时间:2012-03-28 15:40:03.0
改正下我的错误代码 ,谢谢
oView.innerText=document.all( "oSelect1 ").options[selectedIndex].value;
其中oView是个DIV  
  oSelect1是个下拉框
      提示错误   没有selectedIndex的定义
   




------解决方案--------------------
oView.innerText=document.all.oSelect1.options[selectedIndex].value;
------解决方案--------------------
下拉框的value就是其选中的option的value...
------解决方案--------------------
oView.innerText=document.all.oSelect1.options[selectedIndex].value;
selectedIndex为数值就012345……
------解决方案--------------------
实在要写的话

oView.innerText=document.all.oSelect1.options[document.all.oSelect1.selectedIndex].value;
------解决方案--------------------
<body>
<form>
<select id= "oSelect1 " onchange= "document.all.oView.value=this.options[this.selectedIndex].value ">
<option value= "1 "> 1 </option>
<option value= "2 "> 2 </option>
</select>
<input type= "text " id= "oView " value= " ">
</form>
  相关解决方案