【转】jsp 页面 按回车键 触发事件

转载: https://blog.csdn.net/ludongshun2016/article/details/59536779


第一种:

<script type="text/JavaScript">
    function keyOnClick(e){
    var theEvent = window.event || e;
    var code = theEvent.keyCode || theEvent.which;
    if (code==13) {  //回车键的键值为13
        search();  //调用搜索事件
    }
}
</script>

<body onkeydown="keyOnClick(event);">
</body>
 

第二种:

<a href="javascript:void(0)" id="searchBtn" onclick="search()">搜索</a>

<input id="searchKeyword" type="text" value="" size="30"
onkeydown="javascript:if(event.keyCode==13) search();"
placeholder="请输入模糊关键字" name="keyword"> 
或:
<input id="searchKeyword" type="text" value="" size="30"
onkeydown="javascript:if(event.keyCode==13) document.getElementById('searchBtn').click();"
placeholder="请输入模糊关键字" name="keyword">


转载: https://blog.csdn.net/ludongshun2016/article/details/59536779
 

猜你喜欢

转载自www.cnblogs.com/day1day1up/p/11118831.html