Case 1: Carriage return to implement tab jump.
responds to the onkeydown event of the text box, Window.event.keyCode gets the keycode that the user clicked on.
(*) KeyCode and ASCII are not exactly the same, the main keyboard 1 and the keypad 1 of the ASCII, but KeyCode is not the same. The keycode of the carriage return is the keycode of 13,tab 9.
<body onkeydown= "if (window.event.keycode==13) {window.event.keycode=9;}" >
only a few keys can be replaced, most of them are not, have permission problems.
The
keyboard code is not the same as the ASCII code.
KeyCode
8: Backspace
46:delete
37-40: Directional key
48-57: Digital
in keypad area
96-105: Digital
in the main keyboard area
110, 190: decimal point for keypad area and main keyboard area
189, 109: Keypad area and main keyboard area minus
13: Return
9:tab is the one that moves the focus to the next text box.
Case 2: Amount text box
The financial related system includes the following requirements for the amount of text boxes:
Enter Amount text text box does not use Chinese Input method
cannot enter non-digital
The text box when the focus is in the text box, and the text box is right-aligned when the focus leaves the text box, displaying the thousand-bit
Disable Input Method: style= "ime-mode:disabled"//compatible FF, IE, not compatible with Chrome
Prohibit typing illegal values, only these can be typed (k = = 9) | | (k = = 13) | | (k==46) | | (k==8) | | (k==189) | | (k==109) | | (k==190) | | (k==110) | | (k>=48 && k<=57) | | (k>=96 && k<=105) | | (k>=37 && k<=40). Onkeydown= "return Numonkeydown ()" Do not write onkeydown= "Numonkeydown ()" to differentiate between event response functions and function calls to event response functions.
prohibit pasting (great Tester), <input onpaste= "return false;", too violent, should simply prohibit pasting illegal values. Clipboarddata.getdata (' Text ') in Onpaste to the value in the Pasteboard, and then iterate through each character to see if it is a valid value, if all is legal value to allow pasting, as long as there is an illegal value is prohibited paste. CharAt, charCodeAt (check character set. doc)
The
focus is left-aligned with no thousand points, and right-aligned when the focus is not in place. This.style.textalign= ' right '
Add the method of thousand points, see note (*)
======== Supplementary Knowledge ==================
(? =exp) matches the position of the exp front
(? =exp) is also called the 0-width positive lookahead assertion, which asserts that the position in which it appears is followed by the expression exp. For example \b\w+ (? =ing\b), matches the front part of the word with ing ending (except for the part of ING), such as finding I ' m singing while you ' re dancing. When it matches sing and Danc.
===============================
Copy Code code as follows:
function f () {
var txts=document.getelementsbytagname (' input ');
for (Var i=0;i<txts.length;i++) {
Return to Tab
Txts[i].onkeydown=function () {
if (window.event.keycode==13) {
window.event.keycode=9;
}
}
Txts[i].onpaste=function () {
var usrinput=clipboarddata.getdata (' Text ');
var k;
for (Var i=0;i<usrinput.length;i++) {
K=usrinput.charcodeat (i);
You can only paste. or 0-9 of the numbers, refer to the ASCII character set.
if ((k==46) | | (k>=48 && k<=56)) {
}else{
return false;
}
}
}
}
}
(Practice code):
Copy Code code as follows:
function Commafy (n)
{
var re=/\d{1,3} (? = (\d{3}) +$)/g; Must end With \d{3}, preceded by a number of 1-3 digits, but not the ending \d{3} number when replaced. var n1=n.replace (/^) (\d+) ((\.\d+)?) $/,function (S,S1,S2) {return s1.replace (re, $&, ") +s2;});
return N1;
}
function Addqianfenwei (txtbox)
{
Txtbox.value=commafy (Txtbox.value);
}
function Removeqianfenwei (txtbox)
{
Txtbox.value=txtbox.value.replace (/,/g, "");/if replace (', ', ') is replaced by the first
}
Copy Code code as follows:
<script type= "text/javascript" >
function Commafy (n)
{
var re=/\d{1,3} (? = (\d{3}) +$)/g; Match 1 to 3 digits followed by 3 digits, but excluding the last 3 digits.
var n1=n.replace (/^) (\d+) ((\.\d+)?) $/,function (S,S1,S2) {return s1.replace (re, $&, ") +s2;});
return N1;
}
Function Setqfw () {
var Objtxt=document.getelementbyid (' Txtqfw ');
var r= ';
for (Var i=objtxt.value.length-1;i>=0;i--) {
if (i%3==0) {
R+=objtxt.value.charat (i) + ', ';
}else{
R+=objtxt.value.charat (i);
}
}
Objtxt.value=r;
//objtxt.value=commafy (Objtxt.value);
}
</script>