<html>
<head>
</head>
<body>
<select name="menu1" id="menu1">
<option value="http://www.espn.com">ESPN</option>
<option value="http://www.cnn.com">CNN</option>
<option value="http://www.abcnews.com">ABC</option>
<option value="http://www.cbsnews.com">CBS</option>
<option value="http://www.foxnews.com">FOX</option>
</select>
<script type="text/javascript">
var urlmenu = document.getElementById( 'menu1' );
urlmenu.onchange = function() {
window.open( this.options[ this.selectedIndex ].value );
};
</script>
</body>
</html>
我有这个代码,我想通过点击我页面中的选择来打开!不开别的!谢谢!
最佳答案
使用这个:
urlmenu.onchange = function() {
window.open( this.options[ this.selectedIndex ].value, '_self');
};
window.open(URL、名称、规范、替换): 其中名称:
_blank - URL is loaded into a new window. This is default
_parent - URL is loaded into the parent frame
_self - URL replaces the current page
_top - URL replaces any framesets that may be loaded
name - The name of the window (Note: the name does not specify the title of the new window)
关于javascript - 如何使 onchange 下拉选项-url 在我的页面中打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20741512/