- 目的:点击回车键时触发按钮的方法,比如按回车搜索等功能
- 实现:
html:
<!-- 搜索按钮 -->
<button id="btnSle" onclick="doSearch()">搜索</button>
js:
// 初始化
$(function() {
// 绑定回车键
$("body").keydown(function() {
if (event.keyCode == "13") { // keyCode=13是回车键
$('#btnSle').click();
}
});
});
// 搜索方法
function doSearch() {
// 搜索具体操作
}