2017年1月2日 星期一

jquery input search enter ajax json

ow to check if an enter key is pressed with jQuery (這招好)
jQuery function execute on Button Click and Enter/Return (key)
Insert Data Using jQuery Ajax in Asp.net C# [Database MS SQLServer]
---
引用來源

<html>
<head>

<script type="text/javascript" src="jquery-1.4.2.min.js"></script>

</head>
<body>
  <h1>Check if "enter" is pressed with jQuery</h1>

<label>TextBox : </label>
<input id="textbox" type="text" size="50" />

<script type="text/javascript">

$('#textbox').keypress(function(event){

    var keycode = (event.keyCode ? event.keyCode : event.which);
    if(keycode == '13'){
        alert('You pressed a "enter" key in textbox');
    }
    event.stopPropagation();
});

$(document).keypress(function(event){

    var keycode = (event.keyCode ? event.keyCode : event.which);
    if(keycode == '13'){
        alert('You pressed a "enter" key in somewhere');
    }

});

</script>
</body>
</html>

沒有留言:

張貼留言