监听enter(回车)事件

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery监听enter(回车)</title>
<script src="http://test-wx.ixincheng.com//xcview/js/common/jquery-2.1.1.min.js"></script>
<style>
</style>
</head>
<body>
<input type="text" id="search_input">输入框按回车看看效果
<script>
//回车事件绑定  
$('#search_input').bind('keypress', function(event) {
    if (event.keyCode == "13") {
        event.preventDefault();
alert("回车啦");
        //回车执行查询  
        $('#search_button').click();
    }
});
</script>
</body>

</html>

猜你喜欢

转载自blog.csdn.net/qq_38881495/article/details/80069340