zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    PAT之我要通过
    卡拉兹(Callatz)猜想
    数组元素循环右移问题
    Reorder List
    一个fork的面试题
    内存流和null字节
    标准C IO函数和 内核IO函数 效率(时间)比较
    由fdopen和fopen想到的
    VS经常报错的link error 2019
    VS快捷键设置
  • 原文地址:https://www.cnblogs.com/keta/p/9203517.html
Copyright © 2011-2022 走看看