打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
按回车跳转到下一个框 HTML,在输入框中按回车键的光标自动跳到下一个输入框【原创】...
userphoto

2022.09.19 湖南

关注

1 <form name="f1" method="post" action=""> 2 <div class="form-group"> 3 <label for="">编号<i>*</i></label> 4 <input class="form-control" type="text" name="code" id="code" value="" autocomplete="off" onkeypress="if(event.keyCode==13) focusNextInput(this);" /> 5 </div> 6 <div class="form-group"> 7 <label for="">IQC单号<i>*</i></label> 8 <input class="form-control" type="text" name="iqc_bno" id="iqc_bno" value="" autocomplete="off" onkeypress="if(event.keyCode==13) focusNextInput(this);"/> 9 </div>10 <div class="form-group">11 <label for="">入库数量<i>*</i></label>12 <input class="form-control" type="text" name="qty" id="qty" value="" autocomplete="off" onkeypress="if(event.keyCode==13) focusNextInput(this);"/>13 </div>14 <div class="form-group">15 <label for="">操作员<i>*</i></label>16 <input class="form-control" type="text" name="staff" id="staff" autocomplete="off" onkeypress="if(event.keyCode==13) focusNextInput(this);"/>17 </div>18 <div class="form-group">19 <label for="">物料编号<i>*</i></label>20 <input class="form-control" type="text" name="mcode" id="mcode" value="" autocomplete="off" onkeypress="if(event.keyCode==13) focusNextInput(this);"/>21 </div>22 23 <div class="form-group" style="text-align:center">24 <button class="btn btn-success" type="button" id="btn_submit" onclick="check_form()" style="width:100%;">提交</button>25 </div>26 </form>

在项目中,为了方便客户使用,提高客户体验性,在PC端要求在输入框中按键盘的回车键能够执行相应的操作,以下代码可实现:在一个输入框按回车键后光标跳到下一个输入框,如果当前光标所在位置为最后夜歌输入框,则回到第一个输入框。

1.在input标签中调用方法focusNextInput

2.在js中定义方法focusNextInput

function focusNextInput(thisInput)

{

var inputs = document.getElementsByTagName(“input”);

for (var i = 0; i < inputs.length; i++) {

// 如果是最后一个,则焦点回到第一个

if(i==(inputs.length-1)){

inputs[0].focus(); break;

}else if(thisInput == inputs[i]){

inputs[i+1].focus(); break;

}

window.onload = function () {18 document.getElementsByName('code')[0].focus();

​}

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
bootstrap4 textarea
免费刷票软件,如何自己制作?
自动投票机,是如何制作的?
layui开关遇见的坑以及用法总结
LayUI【基本使用】
thymeleaf中跳转地址的使用
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服