Onchange函数不工作

onchange function not working

本文关键字:工作 函数 Onchange      更新时间:2023-09-26
<script type="text/javascript">
function urlchange() {
   var val = document.getElementById('fix');
   e = val.options[val.selectedIndex].value;
   window.open('e','mywindow','width=500,height=500')
}
</script>
</head>
<body>
<select id="fix" onblur="urlchange()">
   <option selected="selected">select</option>
   <option value="http://www.airtel.in">airtel</option>
   <option value="http://google.in">google</option>
</select>
</body>
</html>

你已经写了这段代码火灾时,它是模糊....!!如果你想要onchange,那么试试这个:

<script type="text/javascript">
function urlchange() {
var val= document.getElementById('fix');
e=val.options[val.selectedIndex].value;


window.open(e,'mywindow','width=500,height=500')
}

</script>

<select id="fix" onchange="urlchange()">
<option selected="selected">select</option>
<option value="http://www.airtel.in">airtel</option>
<option value="http://google.in">google</option>
</select>

变量不要加引号

window.open(e,'mywindow','width=500,height=500')

如果你这样做,它将尝试导航到新窗口'e',而不是html中的url。

http://jsfiddle.net/9cMRq/