<form>
<input type="text" id="gover_search_key"><button type="button" onclick="search()"><i class="fa fa-search" aria-hidden="true"></i>
</button>
</form>
function search(){
//alert("test");
keyword=$("#gover_search_key").val();
turnkeyword = escape(keyword);
kuaizhao.href="snapshot.html?a="+turnkeyword;
liebiao.href="search.html?a="+turnkeyword;
str=8;
$.ajax({
type:"GET",
url:'search.php',
dataType:"json",
data:{'keyword':keyword,'page':str
},
success: function (data) {
//alert("test");
var html='';
inum=8;
if(inum>eval(data)[0][4][0])
{inum=eval(data)[0][4][0];}
for(i=0;i<inum;i++){
html=html+'<div class="row zldx_clearfix" ><div class="col_l zldx_fl"><h3>'+eval(data)[0][0][i]+'</h3><p>Added on 2016-08-19 02:05:17 GMT</p><h5>'+eval(data)[0][2][i]+'</h5><a href="#">详情</a></div><div class="col_r"><h4>'+eval(data)[0][1][i]+'</h4></div></div>';
}
$("#container").html(html);
}
}
)
}
给搜索框添加回车事件
document.onkeydown=function(event)
{
e = event ? event :(window.event ? window.event : null);
if(e.keyCode==13){
//执行的方法
alert('回车检测到了');
search();
return false; <span style="color:#ff0000;">//阻止回车之后的页面刷新而使得搜索的事件读不到</span>
}
}
或者
$('#gover_search_key').bind('keypress', function (event) {
if (event.keyCode == "13") {
alert("test");
search();
return false; <pre name="code" class="javascript">//阻止回车之后的页面刷新而使得搜索的事件读不到
} });
效果是一样的