0%

input绑定回车事件

html部分:

1
<input id="search-key" type="text" placeholder="请输入关键字">

JavaScript部分:

1
2
3
4
5
6
7
$('#search-key').keypress(function(event) {
var key = event.which;
console.log(key);
if(key == 13){
//do something
}
});