我有一個jQuery搜索腳本,它使用on keyup函數來提交查詢。如何在用戶按下回車鍵時進行搜索?從jQuery搜索腳本中刪除keyup
這裏是我當前的代碼:
$(document).ready(function(){
$("#search").keyup(function(){
var search=$(this).val();
var query=encodeURIComponent(search);
var yt_url='search.php?q='+query+'&page=1';
window.location.hash='search/'+query+'/1/';
document.title=$(this).val()+" - My Search Script";
$.ajax({
type:"GET",
url:yt_url,
dataType:"html",
success:function(response){
$("#result").html(response);
}
});
});
if(window.location.hash.indexOf('#search/')==0){
query=window.location.hash.replace('#search/', '').replace('/1/', '');
$('#search').val(decodeURIComponent(query)).keyup();
}
});