<!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>