记录一个JQUERY模仿序列号输入
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>无标题文档</title> <script language="javascript" src="js/jquery-1.4.1.min.js"></script> <script language="javascript"> function autoFocus(objId){ var id = "macAddr"+(objId+1); var next = document.getElementById(id); if(document.getElementById("macAddr"+objId).value.length>=4 && next!=undefined){ //alert("asdf"); next.focus(); } } $(document).ready(function(){ $(":input[id^='macAddr']").bind('keyup', handleAddr); }); function handleAddr(){ var current = this; var currvalue = current.value; var reg = /[^\A-Fa-f0-9]|_/ig; var index = parseInt(current.id.substring(7)) ; autoFocus(index); } </script> </head> <body> <input name="textfield" type="text" id="macAddr1" size="4" maxlength="4" /> - <input name="textfield2" type="text" id="macAddr2" size="4" maxlength="4" /> - <input name="textfield3" type="text" id="macAddr3" size="4" maxlength="4" /> - <input name="textfield4" type="text" id="macAddr4" size="4" maxlength="4" /> </body> </html>
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步