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(); } }