JQuery implements the Enter key to switch the focus of a text box
- 2020-03-30 02:51:47
- OfStack
Here's how:
<script src="http://yige.org/static/js/j.js"></script>
jQuery(function () {
jQuery('input:text:first').focus();//Navigate directly to the first text box on the current page
var $inp = jQuery('input:text');//All text fields
$inp.bind('keydown', function (e) {
var key = e.which;
if (key == 13) {
e.preventDefault();
var nxtIdx = $inp.index(this) + 1;
jQuery(":input:text:eq(" + nxtIdx + ")").focus();
}
});
});