日期:2014-05-17  浏览次数:20694 次

ie9,10下的js问题
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
<script type="text/javascript" src="jquery-1.10.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#t").click(function(){
show();
});
});
function show() {
alert(1);

}
function BindEnter(event) {
if (event.keyCode == 13) {
show();
event.cancelBubble = true;
event.returnValue = false;
}
}
</script>
</head>
<body >
<div onkeypress="BindEnter(event)" style="width:200px;height:200px;background-color:red;margin-bottom:100px;">
<input type="text"/>
</div>

<button id="t">test</button>
</body>
</html>


代码如上,用过jquery的都看得懂,问题是:ie9,10下,弹出了两个alert(1),真是百思不得其解!
js 兼容ie

------解决方案--------------------
焦点在test按钮上时,按回车键相当于响应了两次show函数。

------解决方案--------------------
很好奇,是不是你的浏览器出问题了,我测试了几个IE9,IE10都没有出现你说的那些问题!!jquery版本我和你用的是一样的。