1.jQuery implementation Press ESC to clear the information function
function Clearlogs () {
$ (". Logs"). empty ();
}
$ (document). Ready (function () {
$ (window). KeyUp (function (e) {
if (e.keycode==27) {//here represents pressing the ESC key of the keyboard
Clearlogs ();
}
});
});
2. Extensions:
In fact, jquery provides the. Which property to determine if the key is pressed, and the following code can determine
<script type= "Text/javascript" src= "/jquery/jquery.js" ></script>
<script type= "Text/javascript" >
$ (document). Ready (function () {
$ ("input"). KeyDown (function (event) {
$ ("div"). html ("Key:" + Event.which);
});
});
</script>
<body>
Please feel free to type some characters: <input type= "text"/> <p> when you type text in the box above, the following div displays the keyed sequence number. </p> <div/>
</body>
jquery implements press ESC to clear the information function