JavaScript搜索框响应事件

HTML页面,注意:不要使用form标签

<input type = "text" name="keyword" id="keyword"  onkeydown="entersearch()"/>  
<input type = "text" name="keyword" id="keyword"  onkeydown="entersearch1(event)"/>  
<input type = "button" onclick="search()"/>  

 

 

1<input type = "text" name="keyword" id="keyword"  onkeydown="entersearch()"/>
2<input type = "text" name="keyword" id="keyword"  onkeydown="entersearch1(event)"/>
3<input type = "button" onclick="search()"/>

Javascript实现方法

// onclick事件  
function search(){  
    var $keyword = $("#keyword").val();  
    window.location.href = "/list-0-0-0-0-"+$keyword+"-0-0-1.html";  
}  
  
// 按Enter键,执行事件  
function entersearch(){  
    var event = window.event || arguments.callee.caller.arguments[0];  
    if (event.keyCode == 13)  
       {  
          search();  
       }  
}  
  
// 按Enter键,执行事件  
function entersearch1(event){  
    if (event.keyCode == 13)  
       {  
          search();  
       }  
}  
posted @ 2017-05-27 21:29  zxzhang  阅读(1450)  评论(0编辑  收藏  举报