<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
通过按Enter键在表单之间切换的Javascript代码。
<script type="text/javascript">
$(document).on('keypress','input,select',function (e) {
if (e.which == 13) {
e.preventDefault();
var $next = $('[tabIndex=' + (+this.tabIndex + 1) + ']');
console.log($next.length);
if (!$next.length) {
$next = $('[tabIndex=1]');
}
$next.focus();
}
});
</script>
<body>
创建表格
<input type="number" name="" tabindex="1">
<input type="number" name="" tabindex="2">
<input type="number" name="" tabindex="3">
<input type="number" name="" tabindex="4">
</form>
</body>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-
q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
</html>
我尝试了许多方法,但在线工作的代码无法在我的计算机上工作。