JS Monitor Browser return event, you can support ie6+, Firefox, Google and other browsers.
Copy Code code as follows:
<script type= "Text/javascript" >
Registering keyboard events
Document.onkeydown = function (e) {
Catch carriage return events
var ev = (typeof event!= ' undefined ')? Window.event:e;
if (Ev.keycode = = 13) {
Alert (' captures the carriage return event! ');
}
}
</script>
<body/>
So, how do I capture the carriage return event for a specified DOM object? Here take the input tag as an example to illustrate:
Copy Code code as follows:
<script type= "Text/javascript" >
Registering keyboard events
Document.onkeydown = function (e) {
Catch carriage return events
var ev = (typeof event!= ' undefined ')? Window.event:e;
if (Ev.keycode = && Document.activeElement.id = = "MSG") {
Alert ("Get to Content:" + document.activeElement.value);
}
}
</script>
<body>
<input type= "text" id= "msg" value= "/>
</body>
So, JS How to disable browser carriage return event? We know that in an HTML form area, the default behavior of the browser when you press ENTER is to submit the form automatically. Here is an example of how JS disables the browser carriage return event:
Copy Code code as follows:
<script type= "Text/javascript" >
Registering keyboard events
Document.onkeydown = function (e) {
Catch carriage return events
var ev = (typeof event!= ' undefined ')? Window.event:e;
if (Ev.keycode = && Document.activeElement.id = = "MSG") {
Return false;//disabled carriage returns events
}
}
</script>
<body>
<form action= "form.php" >
<input type= "text" id= "msg" Name= "msg" value= ""/>
<input type= "Submit" value= "Submit"/>
</form>
</body>