本来是想用js代码去模拟键盘按下来实现该功能,但是没有实现到。后来想到一种比较笨的方法。局限性是只能这些表单元素只能在同个层面下才能切换。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<input type="text" id="i1" onKeyPress="Myenter('i2')">
<input type="text" id="i2" onKeyPress="Myenter('i3')">
<input type="text" id="i3" onKeyPress="Myenter('i1')">
<button class="btn">
123
</button>
<script>
function Myenter(id) {
if (event.keyCode == 13){
document.getElementById(id).focus();
}
}
window.onload = function() {
}
</script>
</body>
</html>
原理很简单啦