1. 程式人生 > >JS實現搜尋框繫結回車鍵示例

JS實現搜尋框繫結回車鍵示例

<html>
<head>
<script>
window.onload = function(){
 
}


function check() {
var bt = document.getElementById("bt");
var key = event.keyCode;
if (key == 13)
    bt.click();       
}


function test() {
var txtValue = document.getElementById("txt").value;
alert(txtValue);
}

</script>
</head>
<body>
<input type="text" id="txt" value="" onkeypress="return check()" />
<input type="button" id="bt"value="確 定" onclick="test()">
</body>
</html>