jQuery 回车换行、input悬浮全选...

126 阅读1分钟
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="jquery-3.4.1.js"></script>
  <script>
    $(function () {
      // 案例一: 回车换行
      // $('input').keyup(function (e) {
      //   console.log(e);
      // })
      // $('input').on('keyup', function (e) {
      //   if (e.keyCode === 13) {
      //     // 按了回车键,跳转到下一行
      //     $(this).next().next().focus();
      //     // 转成js对象调用 focus() 也是一样。
      //     // $(this).next().next()[0].focus();
      //   }
      // })

      // 案例二: 放上去光标出来
      // $('input').on('mouseenter', function (e) {
      //   $(this).focus()
      // })

      // 案例三: 放上去全部选择光标出来
      // $('input').on('mouseenter', function (e) {
      //   $(this).select()
      // })
    })
  </script>
</head>
<body>
  <input type="text" value="dzm"><br>
  <input type="text" value="dzm"><br>
  <input type="text" value="dzm"><br>
  <input type="text" value="dzm"><br>
  <input type="text" value="dzm"><br>
  <input type="text" value="dzm"><br>
  <input type="text" value="dzm"><br>
  <input type="text" value="dzm"><br>
  <input type="text" value="dzm"><br>
</body>
</html>
  • 案例一:

  • 案例二:

  • 案例三: