[英]IE7 on pressing “enter” key does not prevent default action
我有一個包含的表格
<button class="submit">Submit</button>
和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
});
所以,我想知道我在IE7中做錯了什么,當我輸入搜索詞然后按Enter鍵進入我的主頁(action in form =“/”)。 為什么它不會阻止IE7進入默認操作。
附加說明:
謝謝病毒
您正在阻止按鈕標記的默認操作,這不會影響輸入觸發的事件,還要注意jQuery Event對象的preventDefault()
方法是跨瀏覽器的,請嘗試以下操作:
$('input').on('keyup', function(e){
if (e.which == 13) {
e.preventDefault();
}
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.