Next we use jquery to implement return enter to switch focus, which is passed in the common browsers IE7, IE8, Firefox 3, Chrome 2, and Safari 4 test.
The development tool used is the Microsoft Vs2010+jquery framework
The following steps are implemented
1, first reference jquery class library
<script src= "Scripts/jquery-1.4.1.min.js" type= "Text/javascript" ></script>
2. JavaScript code
Copy Code code as follows:
<script type= "Text/javascript" >
$ (function () {
$ (' Input:text:first '). focus ();
var $inp = $ (' Input:text ');
$inp. Bind (' KeyDown ', function (e) {
var key = E.which;
if (key = = 13) {
E.preventdefault ();
var nxtidx = $inp. Index (this) + 1;
$ (": Input:text:eq (" + Nxtidx + ")"). focus ();
}
});
});
</script>
Analysis:
$ (' Input:text:first '). focus ();
When the page is initialized, focus is positioned in the first text box
var $inp = $ (' Input:text ');
Collection of elements from the type= text box
$inp. Bind (' KeyDown ', function (e) {}
Binding the ' KeyDown ' event to a collection of text boxes
var key = E.which;
The key value of the currently pressed key such as Enter =13
E.preventdefault ();
There are other things that can stop the default behavior of it, where we organize postback, instead of switching focus. Another similar approach is stoppropagation, which plays a role in blocking JS event bubbling.