[英]IE7 on pressing “enter” key does not prevent default action
I have a form which contains 我有一个包含的表格
<button class="submit">Submit</button>
and jQuery code 和jQuery代码
$(".submit").click(function(e){
var evt = e || window.event; // IE compatibility
if(evt.preventDefault){
evt.preventDefault();
}else{
evt.returnValue = false;
evt.cancelBubble=true;
}
//....ajax call
});
So, I was wondering what am I doing wrong that in IE7 when I type search term and press enter it goes to my home page(action in form ="/"). 所以,我想知道我在IE7中做错了什么,当我输入搜索词然后按Enter键进入我的主页(action in form =“/”)。 Why it does not prevent IE7 from going to default action.
为什么它不会阻止IE7进入默认操作。
Additional note: 附加说明:
Thanks Viral 谢谢病毒
You are preventing the default action of the button tag, which does not affect input triggered events, also note that jQuery Event object preventDefault()
method is cross-browser, try this: 您正在阻止按钮标记的默认操作,这不会影响输入触发的事件,还要注意jQuery Event对象的
preventDefault()
方法是跨浏览器的,请尝试以下操作:
$('input').on('keyup', function(e){
if (e.which == 13) {
e.preventDefault();
}
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.