ENTER to move the cursor to the next input box
<Input onkeydown = "if (event. keyCode = 13) event. keyCode = 9">
Only Chinese
<Input onkeyup = "value = value. replace (/[-~] /G, '')" onkeydown = "if (event. keyCode = 13) event. keyCode = 9">
Only English and numbers are allowed. The input method is blocked.
<Input style = "ime-mode: disabled" onkeydown = "if (event. keyCode = 13) event. keyCode = 9">
Only English and numbers can be entered.
<Input onkeyup = "value = value. replace (/[\ W]/g, '')" onbeforepaste = "clipboardData. setData ('text', clipboardData. getData ('text '). replace (/[^ \ d]/g, '')" onkeydown = "if (event. keyCode = 13) event. keyCode = 9 ">
Only numbers are allowed.
<Input onkeyup = "value = value. replace (/[^ \ d]/g, '')" onbeforepaste = "clipboardData. setData ('text', clipboardData. getData ('text '). replace (/[^ \ d]/g, '')">
Display only, text box that cannot be modified
<Input readOnly value = "display only, cannot be modified">
Only numbers are allowed. The code for judging the buttons is as follows:
<Script language = javascript>
Function onlyNum ()
{
If (! (Event. keyCode> = 48 & event. keyCode <= 57) | (event. keyCode> = 96 & event. keyCode <= 105) | (event. keyCode = 8 )))
Event. returnValue = false;
}
</Script>
<Input onkeydown = "onlyNum ();">
Appendix: Obtain the KeyCode of the keyboard
<Html>
<Head>
<Script language = "javascript">
Ns4 = (document. layers )? True: false;
Ie4 = (document. all )? True: false;
Function keyDown (e ){
If (ns4 ){
Var nkey = e. which;
Var iekey = 'ns browser now ';
Var realkey = String. fromCharCode (e. which );
}
If (ie4 ){
Var iekey = event. keyCode;
Var nkey = 'ie browser now ';
Var realkey = String. fromCharCode (event. keyCode );
If (event. keyCode = 32) {realkey = '\ 'space \''}
If (event. keyCode = 13) {realkey = '\' press enter \''}
If (event. keyCode = 27) {realkey = '\ 'esc \''}
If (event. keyCode = 16) {realkey = '\ 'shift \''}
If (event. keyCode = 17) {realkey = '\ 'ctrl \''}
If (event. keyCode = 18) {realkey = '\ 'alt \''}
}
Alert ('ns browser key value: '+ nkey +' \ n' + 'ie browser key value: '+ iekey +' \ n' + 'actual key is' + realkey );
}
Document. onkeydown = keyDown;
If (ns4 ){
Document. captureEvents (Event. KEYDOWN );}
</Script>
</Head>
<Body>
// Javascript Document.
<Hr>
<Center>
<H3> press any key .... </H3>
</Center>
</Body>
</Html>
Restrict webpage keyboards
<Body onkeydown = "alert ('offset'); return false;">
Restrict a keyboard key:
<Body onkeydown = "if (event. keyCode = num) {alert ('offset'); return false ;}>
Add another key value.
<Script>
Function show (){
Alert ("ASCII Code:" + event. keyCode );
}
</Script>
<Body onkeydown = "show ()">
Only IP addresses are allowed.
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Meta name = "GENERATOR" content = "Microsoft FrontPage 4.0">
<Meta name = "ProgId" content = "FrontPage. Editor. Document">
<Style>
. A3 {width: 30; border: 0; text-align: center}
</Style>
<Script>
Function mask (obj ){
Obj. value = obj. value. replace (/[^ \ d]/g ,'')
Key1 = event. keyCode
If (key1 = 37 | key1 = 39)
{Obj. blur ();
Nextip = parseInt (obj. name. substr (2, 1 ))
Nextip = key1 = 37? Nextip-1: nextip + 1;
Nextip = nextip> = 5? 1: nextip
Nextip = nextip <= 0? 4: nextip
Eval ("ip" + nextip + ". focus ()")
}
If (obj. value. length> = 3)
If (parseInt (obj. value)> = 256 | parseInt (obj. value) <= 0)
{
Alert (parseInt (obj. value) + "ip address error! ")
Obj. value = ""
Obj. focus ()
Return false;
}
Else
{Obj. blur ();
Nextip = parseInt (obj. name. substr (2, 1) + 1
Nextip = nextip> = 5? 1: nextip
Nextip = nextip <= 0? 4: nextip
Eval ("ip" + nextip + ". focus ()")
}
}
Function mask_c (obj)
{
ClipboardData. setData ('text', clipboardData. getData ('text'). replace (/[^ \ d]/g ,''))
}
</Script>
<Title> ip address input </title>
</Head>
<Body> ip address input
<Div style = "border-width: 1; border-color: balck; border-style: solid; width: 165; font-size: 9pt">
<Input type = text name = ip1 maxlength = 3 class = a3 onkeyup = "mask (this)" onbeforepaste = mask_c ()>.
<Input type = text name = ip2 maxlength = 3 class = a3 onkeyup = "mask (this)" onbeforepaste = mask_c ()>.
<Input type = text name = ip3 maxlength = 3 class = a3 onkeyup = "mask (this)" onbeforepaste = mask_c ()>.
<Input type = text name = ip4 maxlength = 3 class = a3 onkeyup = "mask (this)" onbeforepaste = mask_c ()>
</Div>
</Body>
</Html>
Use # default # savehistory to prevent the text box from being cleared after the rollback:
<HTML>
<HEAD>
<Meta name = "save" CONTENT = "history">
<STYLE>
. SaveHistory {behavior: url (# default # savehistory );}
</STYLE>
</HEAD>
<BODY>
<INPUT class = saveHistory type = text id = oPersistInput>
<Input type = button onclick = 'javascript: location. href = "http://www.webjx.com/" 'value = 'click to enter, then press the back key to try? '>
</BODY>
</HTML>
Number of lines of TEXTAREA adaptive text
<Textarea rows = 1 name = s1 cols = 27 onpropertychange = "this. style. posHeight = this. scrollHeight">
Upload preview Image
<Input type = file name = file> <input type = button onclick = pic. src = file. value = preview image>
<Input type = button onclick = alert (file. value) value = image address>
<Input type = button onclick = "file. outerHTML = file. outerHTML. replace (/value = \ w/g,'') "value =" clear words in file ">
Remove the border from the drop-down list
<Div style = "position: absolute; left: 10px; top: 10px; width: 115px; height: 20px; clip: rect (2 114 20 2);">
<Select>
<Option> cnpeople </option>
<Option> cnrose </option>
<Option> cnbruce </option>
</Select>
</Font>
</Div>
Open a window in the drop-down list
<Select onChange = "if (this. selectedIndex & this. selectedIndex! = 0) {window. open (this. value);} this. selectedIndex = 0; ">
<Option selected> more links ...... </Option>
<Option value = "http://www.cnbruce.com"> cnbruce </option>
<Option value = "http://daonet.myrice.com/old/"> daonet </option>
<Option value = "http://www.blueidea.com"> blue! Dea
</Select>
TAB display
<Script>
Function editTab ()
{
Var code, sel, tmp, r
Var tabs = ""
Event. returnValue = false
Sel listen event.srcelement.doc ument. selection. createRange ()
R = event. srcElement. createTextRange ()
Switch (event. keyCode)
{
Case (8 ):
If (! (Sel. getClientRects (). length> 1 ))
{
Event. returnValue = true
Return
}
Code = sel. text
Tmp = sel. duplicate ()
Tmp. moveToPoint (r. getBoundingClientRect (). left, sel. getClientRects () [0]. top)
Sel. setEndPoint ("startToStart", tmp)
Sel. text = sel. text. replace (/^ \ t/gm ,"")
Code = code. replace (/^ \ t/gm, ""). replace (/\ r \ n/g, "\ r ")
R. findText (code)
R. select ()
Break
Case (9 ):
If (sel. getClientRects (). length> 1)
{
Code = sel. text
Tmp = sel. duplicate ()
Tmp. moveToPoint (r. getBoundingClientRect (). left, sel. getClientRects () [0]. top)
Sel. setEndPoint ("startToStart", tmp)
Sel. text = "\ t" + sel. text. replace (/\ r \ n/g, "\ r \ t ")
Code = code. replace (/\ r \ n/g, "\ r \ t ")
R. findText (code)
R. select ()
}
Else
{
Sel. text = "\ t"
Sel. select ()
}
Break
Case (13 ):
Tmp = sel. duplicate ()
Tmp. moveToPoint (r. getBoundingClientRect (). left, sel. getClientRects () [0]. top)
Tmp. setEndPoint ("endToEnd", sel)
For (var I = 0; tmp. text. match (/^ [\ t] +/g) & I <tmp. text. match (/^ [\ t] +/g) [0]. length; I ++) tabs + = "\ t"
Sel. text = "\ r \ n" + tabs
Sel. select ()
Break
Default:
Event. returnValue = true
Break
}
}
</Script>
<Textarea cols = 75 rows = 20 onkeydown = "editTab ()">
<Script>
Alert ("OK ")
</Script>
</Textarea>
Up/down the text box
<Form name = "cnbruce">
<Textarea name = "com">
</Textarea>
</Form>
<SPAN title = 'enlarge the input box 'style = 'font-SIZE: 12px; CURSOR: hand 'onclick = document.cnbruce.com. rows + = 4> down </SPAN>
<SPAN title = 'zoom out the input box 'style = 'font-SIZE: 12px; CURSOR: hand' class = 'arrow' onclick = 'if (document.cnbruce.com. rows> = 4) document.cnbruce.com. rows-= 4; else return false'> up </SPAN>
One check box. Select all the check boxes after clicking.
<Input type = "checkbox" name = "checkA" onpropertychange = "for (I = 0; I <. children. length; I ++) {. children [I]. checked = this. checked} ">
<Br>
<Span id = "A">
<Input type = "checkbox" name = "A1">
<Input type = "checkbox" name = "A2">
<Input type = "checkbox" name = "A3">
</Span>
Debug Textarea: something that is used for instant error detection when writing js scripts online!
<HTML>
<HEAD>
<TITLE> Debug Textarea </TITLE>
<Meta http-equiv = 'content-type' Content = 'text/html; charset = gb2312 '>
</HEAD>
<Style>
*{
Font-size: 12px
}
Body {
Margin: 10px; padding: 0px
}
Table. list {
Cursor: default;
Border: 1px solid # cccccc
Background-color: # cccccc;
Border-collapse: collapse;
Border-Color: # cccccc;
}
</Style>
<Script language = "javascript">
// Coded by windy_sk <windy_sk@126.com> 20040205
Function reportError (msg, url, line ){
Var str = "You have found an error as below: \ n ";
Str + = "Err:" + msg + "on line:" + line;
Alert (str );
Return true;
}
Window. onerror = reportError;
Document. onkeydown = function (){
If (event. ctrlKey ){
Switch (event. keyCode ){
Case 82: // r
Runcode ();
Break;
Case 83: // s
Savecode ();
Break;
Case 71: // g
Goto (prompt ('Please input the line number', '1 '));
Break;
Case 65: //
Document.exe cCommand ("SelectAll ");
Break;
Case 67: // c
Document.exe cCommand ("Copy ");
Break;
Case 88: // x
Document.exe cCommand ("Cut ");
Break;
Case 86: // v
Document.exe cCommand ("Paste ");
Break;
Case 90: // z
Document.exe cCommand ("Undo ");
Break;
Case 89: // y
Document.exe cCommand ("Redo ");
Break;
Default:
Break;
}
Event. keyCode = 0;
Event. returnValue = false;
}
Return;
}
Function show_ln (){
Var txt_ln = document. getElementById ('txt _ ln ');
Var txt_main = document. getElementById ('txt _ main ');
Txt_ln.scrollTop = txt_main.scrollTop;
While (txt_ln.scrollTop! = Txt_main.scrollTop ){
Txt_ln.value + = (I ++) + '\ n ';
Txt_ln.scrollTop = txt_main.scrollTop;
}
Return;
}
Function editTab (){
Var code, sel, tmp, r
Var tabs =''
Event. returnValue = false
Sel listen event.srcelement.doc ument. selection. createRange ()
R = event. srcElement. createTextRange ()
Switch (event. keyCode ){
Case (8 ):
If (! (Sel. getClientRects (). length> 1 )){
Event. returnValue = true
Return
}
Code = sel. text
Tmp = sel. duplicate ()
Tmp. moveToPoint (r. getBoundingClientRect (). left, sel. getClientRects () [0]. top)
// Error check code ~~~~~~
If (sel. parentElement ()! = Tmp. parentElement () return;
Sel. setEndPoint ('starttostart', tmp)
Sel. text = sel. text. replace (/^ \ t/gm ,'')
Code = code. replace (/^ \ t/gm, ''). replace (/\ r \ n/g, '\ R ')
R. findText (code)
R. select ()
Break
Case (9 ):
If (sel. getClientRects (). length> 1 ){
Code = sel. text
Tmp = sel. duplicate ()
Tmp. moveToPoint (r. getBoundingClientRect (). left, sel. getClientRects () [0]. top)
// Error check code ~~~~~~
If (sel. parentElement ()! = Tmp. parentElement () return;
Sel. setEndPoint ('starttostart', tmp)
Sel. text = '\ t' + sel. text. replace (/\ r \ n/g,' \ r \ t ')
Code = code. replace (/\ r \ n/g, '\ r \ t ')
R. findText (code)
R. select ()
} Else {
Sel. text = '\ t'
Sel. select ()
}
Break
Case (13 ):
Tmp = sel. duplicate ()
Tmp. moveToPoint (r. getBoundingClientRect (). left, sel. getClientRects () [0]. top)
// Error check code ~~~~~~
If (sel. parentElement ()! = Tmp. parentElement () return;
Tmp. setEndPoint ('endtoend', sel)
For (var I = 0; tmp. text. match (/^ [\ t] +/g) & I <tmp. text. match (/^ [\ t] +/g) [0]. length; I ++) tabs + = '\ t'
Sel. text = '\ r \ n' + tabs
Sel. select ()
Break
Default:
Event. returnValue = true
Break;
}
Return;
}
Function runcode (){
Var str = document. getElementById ("txt_main"). value;
Var code_win = window. open ('about: blank ');
Code_win.document.open ();
Code_win.document.writeln ("<script> ");
Code_win.document.writeln ("function reportError (msg, url, line) {\ nline-= 14; \ nvar str = 'you have found an error as below: \ n \ n '; \ nstr + = 'err: '+ msg + 'on line:' + (line); \ nalert (str); \ nopener. goto (line); \ nopener. focus (); \ nwindow. onerror = null; \ nsetTimeout ('self. close () ', 10); \ nreturn true; \ n }");
Code_win.document.writeln ("window. onerror = reportError ;");
Code_win.document.writeln ("<\/script> ");
Code_win.document.writeln (str );
Code_win.document.close ();
Return;
}
Function savecode (){
Var str = document. getElementById ("txt_main"). value;
Var code_win = window. open ('about: blank ',' _ blank ', 'top = 100 ');
Code_win.document.open ();
Code_win.document.writeln (str );
Code_win.document.close ();
Code_win.document.execcommand('saveas', '', 'code.html ');
Code_win.close ();
Return;
}
Function goto (ln ){
If (! /^ \ D + $/. test (ln) return;
Var obj = document. getElementById ("txt_main ");
Var rng = obj. createTextRange ();
Var arr = obj. value. replace (/\ r/, ""). split (/\ n /);
If (ln> arr. length) ln = arr. length;
Var str_tmp = "";
For (var I = 0; I <ln-1; I ++ ){
Str_tmp + = arr [I];
}
Rng. moveStart ('character ', str_tmp.length + 1 );
Str_tmp = "";
For (I = ln; I <arr. length; I ++ ){
Str_tmp + = arr [I];
}
Rng. moveEnd ('character ',-str_tmp.length );
Rng. select ();
Return;
}
Window. onload = function () {document. getElementById ("txt_main"). value = "<script> \ nalert (') \ n <\/script> ";}
</Script>
<BODY>
<Table width = '000000' class = 'LIST' border = '1' bgcolor = '# eeeeeee' bordercolorlight =' #600 'bordercolordark = '# ffff' cellpadding = '0' cellspacing = '0'>
<Tr bgcolor = '# cccccc'>
<Td colspan = '2' height = '20' align = 'center'> <B> Debug Textarea </B> </td>
</Tr>
<Tr>
<Td colspan = '2'>
<Table width = '000000' border = '0' align = 'center'>
<Tr>
<Td align = 'center'> <br/>
<Textarea id = 'txt _ ln 'name = 'content' rows = '10' style = 'width: 40px; overflow: hidden; height: 200px; border-right: 0px; text-align: right; line-height: 14px 'onselectstart = 'this. nextSibling. focus (); return false 'readonly> </textarea> <textarea id = 'txt _ main' name = 'content' rows = '10' cols = '80' onkeydown = 'edittab () 'onkeyup = 'show _ ln () 'onscroll = 'show _ ln ()' wrap = 'off' style = 'overflow: auto; height: 200px; padding-left: 5px; border-left: 0px; line-height: 14px '> </textarea>
<Script> for (var I = 1; I <= 20; I ++) document. getElementById ('txt _ ln '). value + = I + '\ n'; </script>
</Td>
</Tr>
<Tr>
<Td align = 'center'> <br/>
<Input type = 'button 'value = 'onclick = 'runcode ()' accesskey = 'R'> & nbsp;
<Input type = 'button 'value = 'Save 'onclick = 'savecode ()' accesskey = S'> & nbsp;
<Input type = 'button 'value = 'jump to 'onclick = "goto (prompt ('Please input the line number', '1 ')) "accesskey = 'G'> & nbsp;
</Td>
</Tr>
</Table>
</Td>
</Tr>
</Table>
</BODY>
</HTML>
Obtains the non-value of input, but displays the text value.
<Select name = "sss" onChange = "alert (this. options [this. selectedIndex]. text)">
<Option value = "1"> asdf </option>
<Option value = "2"> bbbb </option>
<Option value = "3"> ccc </option>
</Select>
Http://17130.ezhu.com/17130/post/75809/