html頁(yè)面:
<input type = "text" name="keyword" id="keyword" onkeydown="entersearch()"/>
note:注意不要使用form標(biāo)簽
JS事件:
// onclick事件
function search(){
var $keyword = $("#keyword").val();
window.location.href = "/index/"+?keywords=$keyword;
}
// 按Enter鍵,執(zhí)行事件
function entersearch(){
var event = window.event || arguments.callee.caller.arguments[0];
if (event.keyCode == 13)
{
search();
}
}
|