会自动“TAB”的文本框 - 中国WEB开发者网络 (http://www.webasp.net) -- 网页特效 (http://www.webasp.net/javascript/) --- 会自动“TAB”的文本框 (http://www.webasp.net/javascript/1/395.htm) |
| -- 发布日期: 2005-06-07 |
| <!-- 网页特效代码由[中国WEB开发者网络:http://www.ChinaWebDev.com]提供! --> <!-- 要实现此效果需要 2 个步骤: --> <!-- 第 1 步: --> <!-- 把下面的代码加到<HEAD></HEAD>区域中: --> <SCRIPT LANGUAGE="JavaScript"> <!-- Begin var isNN = (navigator.appName.indexOf("Netscape")!=-1); function autoTab(input,len, e) { var keyCode = (isNN) ? e.which : e.keyCode; var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46]; if(input.value.length >= len && !containsElement(filter,keyCode)) { input.value = input.value.slice(0, len); input.form[(getIndex(input)+1) % input.form.length].focus(); } function containsElement(arr, ele) { var found = false, index = 0; while(!found && index < arr.length) if(arr[index] == ele) found = true; else index++; return found; } function getIndex(input) { var index = -1, i = 0, found = false; while (i < input.form.length && index == -1) if (input.form[i] == input)index = i; else i++; return index; } return true; } // End --> </script> <!-- 第 2 步: --> <!-- 把下面的代码加到<BODY></BODY>区域中: --> <center> <form> <table width="400"> <tr> <td> <div align="center"><br> <small> <input onKeyUp="return autoTab(this, 3, event);" size="4" maxlength="3"> </small>- <small> <input onKeyUp="return autoTab(this, 3, event);" size="4" maxlength="3"> </small> - <small> <input onKeyUp="return autoTab(this, 4, event);" size="5" maxlength="4"> </small> - <small> <input onKeyUp="return autoTab(this, 3, event);" size="4" maxlength="3"> </small> - <small> <input onKeyUp="return autoTab(this, 2, event);" size="3" maxlength="2"> </small> - <small> <input onKeyUp="return autoTab(this, 4, event);" size="5" maxlength="4"> </small> </div> </td> </tr> </table> </form> </center> |
| webasp.net |