jQuery回车键快速切换下一个input文本框解决方案

<!DOCTYPE html>
<html lang="en"> <head> <meta charset="UTF-8"> <title>enter</title> <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.2.1.js"></script> </head> <body> <div onkeyup="onEnter()"> <input type="text" name="input" onclick="clickEnter()"> <input type="text" name="input" onclick="clickEnter()"> <input type="text" name="input" onclick="clickEnter()"> <input type="text" name="input" onclick="clickEnter()"> <input type="text" name="input" onclick="clickEnter()"> <input type="text" name="input" onclick="clickEnter()"> <input type="text" name="input" > </div> <script> var index = 0 <!-- function clickEnter() { $('input[name=input]').each(function (i) { if ($(this).is(':focus')) { index = i } }) } --> function onEnter() { if (event.keyCode == 13){ index++ if (index >= $('input[name=input]').length) { index = 0 } $('input[name=input]').each(function (i) { if (i == index) { $(this).focus() } }) } } </script> </body> </html>

猜你喜欢

转载自www.cnblogs.com/keta/p/9203517.html