[英]catch the enter keyup event,while it shows the error 405:method not allowed
I'm writing a keyup event on a search input like: 我在搜索输入上写了一个keyup事件,例如:
$("#searchbox").keyup(function(e){
var curKey = e.which;
var text = $(this).attr("value");
if(curKey == 13){
$(".menu_tab").removeClass("menu_bg");
$(".mainGreyBox").css("display","none");
$("#aboutSearchResult").css("display","block");
}else{
var text = $(this).attr("value");
console.log(text);
$("#searchresult").empty();
var SearchMan = new SearchModel().init(text); //显示search列表
$(".global_acResults").show();
}
I want to show a new page which id is "aboutSearchResult" when I enter the search words and then press the enter on the keyboard.But I find that the page I want to show flash past and then the page shows like: 输入搜索词然后按键盘上的enter时 ,我想显示一个id为“ aboutSearchResult”的新页面。但是我发现我要显示的页面闪过,然后该页面显示如下:
But I don't know why,looking for your help,thanks. 但是我不知道为什么,感谢您的帮助。
ps: #searchbox
is an input element. ps:
#searchbox
是输入元素。
The keydown
event generated when you press the Enter key in the text box is not being handled, and is causing the form that the input element is a member of to be submitted (to a URI that isn't expecting a form to be submitted to it, hence the error). 您在文本框中按Enter键时生成的
keydown
事件未得到处理,并导致提交了input元素所属的表单(不希望将表单提交到的URI)它,因此错误)。
Bind your event handler to keydown
, not keyup
, and include 将事件处理程序绑定到
keydown
而不是keyup
,并包括
event.preventDefault();
in the branch for Enter ( curKey == 13
) to prevent it from triggering the default behavior (of submitting the form). 在Enter的分支中(
curKey == 13
)以防止其触发默认行为(提交表单)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.