Safari 浏览器下 select 不能window.open , button 却可以
为什么?怎么解决这个问题呢?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>测试</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
</head>
<body> <select id="sl">
<option value="1">百度1</option>
<option value="2">百度2</option>
<option value="3">百度3</option>
<option value="4">百度4</option>
<option value="5">百度5</option>
</select> <input type="button" id="btn" value="跳转" />
<script type="text/javascript"> document.getElementById('sl').onchange = function () {
window.open('http://www.baidu.com')
}; document.getElementById('btn').onclick = function () {
window.open('http://www.baidu.com')
}; </script></body>
</html>Safaribug百度HTML浏览器
为什么?怎么解决这个问题呢?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>测试</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
</head>
<body> <select id="sl">
<option value="1">百度1</option>
<option value="2">百度2</option>
<option value="3">百度3</option>
<option value="4">百度4</option>
<option value="5">百度5</option>
</select> <input type="button" id="btn" value="跳转" />
<script type="text/javascript"> document.getElementById('sl').onchange = function () {
window.open('http://www.baidu.com')
}; document.getElementById('btn').onclick = function () {
window.open('http://www.baidu.com')
}; </script></body>
</html>Safaribug百度HTML浏览器
re:
贴出你表单瞧瞧
在页面中加这段
<form id="myform" method="get" action="http://www.baidu.com" target="_blank"></form>然后onchange的时候执行
document.getElementById('myform').submit();
document.getElementById('myform').submit();
re:
哪个标签onchange的时候
代码如下:
<select id="sl">
<option value="1">百度1</option>
<option value="2">百度2</option>
</select>
<form id="myform" method="get" action="http://www.baidu.com" target="_blank"></form>
document.getElementById('sl').onchange = function () {
document.getElementById('myform').submit();
};
select标签中,在onchange中不能写window.open,但是在click的时候可以执行window.open所以我们可以这样写可以解决
<select id="sl">
<option value="1">百度1</option>
<option value="2">百度2</option>
</select>
<input type="hidden" value="1" id="hid" />document.getElementById('sl').onchange = function () {
var that = this;
setTimeout(function(){
document.getElementById('hid').value = that.value;
},0);
};
document.getElementById('sl').onclick = function () {
var oldval = document.getElementById('hid').value;
if(this.value != oldval){
window.open('http://www.baidu.com')
}
};
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>测试</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
</head>
<body>
<form id="myform" method="get" action="http://www.baidu.com">
<select id="sl" onchange="fun1()">
<option value="1">百度1</option>
<option value="2">百度2</option>
<option value="3">百度3</option>
<option value="4">百度4</option>
<option value="5">百度5</option>
</select>
<input type="button" id="btn" value="跳转" />
</form>
<script type="text/javascript">
function fun1(){
document.getElementById('myform').submit();
}
document.getElementById('btn').onclick = function () {
window.open('http://www.baidu.com')
};
</script>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>测试</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<style>
.select{
display:inline-block;
border: solid 1px blue;
width: 100px;
padding: 10px;
text-align: center;
}
.select>div{ }
.select>input{
display: none;
}
.select:hover>div{
display: none;
}
.select:hover>input{
display: block;
width: 100%;
margin-top: 5px;
margin-bottom: 5px;
}
</style>
</head>
<body>
<div class="select">
<div>选择</div>
<input type="button" id="btn1" value="百度" />
<input type="button" id="btn2" value="百度" />
<input type="button" id="btn3" value="百度" />
<input type="button" id="btn4" value="百度" />
<input type="button" id="btn5" value="百度" />
<input type="button" id="btn6" value="百度" />
</div>
<script type="text/javascript">
for(var i = 1; i<=6;i++)
document.getElementById('btn' + i ).onclick = function () {
window.open('http://www.baidu.com');
};
</script>
</body>