![](/img/trans.png)
[英]Fetch error - Receiving 405 GET Method Not Allowed While Using POST
[英]catch the enter keyup event,while it shows the error 405:method not allowed
我在搜索輸入上寫了一個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();
}
輸入搜索詞然后按鍵盤上的enter時 ,我想顯示一個id為“ aboutSearchResult”的新頁面。但是我發現我要顯示的頁面閃過,然后該頁面顯示如下:
但是我不知道為什么,感謝您的幫助。
ps: #searchbox
是輸入元素。
您在文本框中按Enter鍵時生成的keydown
事件未得到處理,並導致提交了input元素所屬的表單(不希望將表單提交到的URI)它,因此錯誤)。
將事件處理程序綁定到keydown
而不是keyup
,並包括
event.preventDefault();
在Enter的分支中( curKey == 13
)以防止其觸發默認行為(提交表單)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.