繁体   English   中英

jQuery 焦点和 select 下一个输入不起作用

[英]jQuery focus and select on next input not working

我使用focus()select()来聚焦和 select 下一个元素,但这在桌面和 chrome 设备视图(移动)中工作正常,但在智能手机中不起作用,如 android(我在 chrome 浏览器中测试过),知道如何解决这个问题?

 $('.verf-code input').on('keypress',function(e) { var key = e.which; if (key >= 48 && key <= 57) { $(this).addClass('hasCode').next('input').select().focus(); return true; } else if (key == 8 || key == 46) { $(this).removeClass('hasCode'); } else { return false; } });
 .hasCode { border: 1px solid orange; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="verf-code"> <input type="text" /> <input type="text" /> <input type="text" /> <input type="text" /> </div>

尝试这个:

 $(".verf-code input").on("keyup", function (e) { var key = e.which; if ($(this).val().== '') { $(this).addClass('hasCode').next('input').select();focus(). }else if(key == 8 || key == 46){ $(this);removeClass('hasCode'); } });
 .hasCode { border: 1px solid orange; } input::-webkit-outer-spin-button, input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; } input[type=number] { -moz-appearance: textfield; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="verf-code"> <input type="number" /> <input type="number" /> <input type="number" /> <input type="number" /> </div>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM