只能是一些限定的东西 ENTER键可以让光标移到下一个输入框 <input onkeydown=if(eventkeyCode==)eventkeyCode= > <br> 只能是中文<input onkeyup=value=valuereplace(/[ ~]/g) onkeydown=if(eventkeyCode==)eventkeyCode=> <br> 屏蔽输入法<input onkeydown=if(eventkeyCode==)eventkeyCode=> <br> 只能输入英文和数字<input onkeyup=value=valuereplace(/[\W]/g) onbeforepaste=clipboardDatasetData(textclipboardDatagetData(text)replace(/[^\d]/g)) onkeydown=if(eventkeyCode==)eventkeyCode=> <br> 只能是数字<input onkeyup=value=valuereplace(/[^\d]/g) onbeforepaste=clipboardDatasetData(textclipboardDatagetData(text)replace(/[^\d]/g))><br> 只能显示不能修改<input readonly value=只能显示不能修改> 只能是数字判断按键的值 <script language=javascript> function onlyNum() { if(!((eventkeyCode>=&&eventkeyCode<=)||(eventkeyCode>=&&eventkeyCode<=)||(eventkeyCode==))) eventreturnValue=false; } </script> <input onkeydown=onlyNum();> 附获取键盘的KeyCode <html> <head> <script language=javascript> ns = (documentlayers) ? true : false; ie = (documentall) ? true : false; function keyDown(e){ if(ns){ var nkey=ewhich; var iekey=现在是ns浏览器; var realkey=StringfromCharCode(ewhich); } if(ie){ var iekey=eventkeyCode; var nkey=现在是ie浏览器; var realkey=StringfromCharCode(eventkeyCode); if(eventkeyCode==){realkey=\ 空格\} if(eventkeyCode==){realkey=\ 回车\} if(eventkeyCode==){realkey=\ Esc\} if(eventkeyCode==){realkey=\ Shift\} if(eventkeyCode==){realkey=\ Ctrl\} if(eventkeyCode==){realkey=\ Alt\} } alert(ns浏览器中键值:+nkey+\n+ie浏览器中键值:+iekey+\n+实际键为+realkey); } documentonkeydown = keyDown; if(ns){ documentcaptureEvents(EventKEYDOWN);} </script> </head> <body> //Javascript Document <hr> <center> <h>请按任意一个键</h> </center> </body> </html> 限制网页用键盘 <body onkeydown=alert(禁用);return false;> 限制键盘的某个键body onkeydown=if(eventkeyCode==num){alert(禁用);return false;} 再加个找按键的值 <script> function show(){ alert(ASCII代码是+eventkeyCode); } </script> <body onkeydown=show()> 只能是IP地址 <html> <head> <meta httpequiv=ContentType content=text/html; charset=gb> <meta name=GENERATOR content=Microsoft FrontPage > <meta name=ProgId content=FrontPageEditorDocument> <style> a{width:;border:;textalign:center} </style> <script> function mask(obj){ objvalue=objvaluereplace(/[^\d]/g) key=eventkeyCode if (key== || key==) { objblur(); nextip=parseInt(objnamesubstr()) nextip=key==?nextip:nextip+; nextip=nextip>=?:nextip nextip=nextip<=?:nextip eval(ip+nextip+focus()) } if(objvaluelength>=) if(parseInt(objvalue)>= || parseInt(objvalue)<=) { alert(parseInt(objvalue)+IP地址错误!) objvalue= objfocus() return false; } else { objblur(); nextip=parseInt(objnamesubstr())+ nextip=nextip>=?:nextip nextip=nextip<=?:nextip eval(ip+nextip+focus()) } } function mask_c(obj) { clipboardDatasetData(textclipboardDatagetData(text)replace(/[^\d]/g)) } </script> <title>IP地址输入</title> </head> <body>IP地址输入 <div > <input type=text name=ip maxlength= class=a onkeyup=mask(this) onbeforepaste=mask_c()> <input type=text name=ip maxlength= class=a onkeyup=mask(this) onbeforepaste=mask_c()> <input type=text name=ip maxlength= class=a onkeyup=mask(this) onbeforepaste=mask_c()> <input type=text name=ip maxlength= class=a onkeyup=mask(this) onbeforepaste=mask_c()> </div> </body> </html> 用#default#savehistory防止后退清空text文本框 <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点击进入再按后退键试试?> </BODY> </HTML> TEXTAREA自适应文字行数的多少 <textarea rows= name=s cols= onpropertychange=thisstyleposHeight=thisscrollHeight> 上传预览图片 <img id=pic src=_//gif> <input type=file name=file><input type=button onclick=picsrc=filevalue value=预览图片> <input type=button onclick=alert(filevalue) value=图片地址> <input type=button onclick=fileouterHTML=fileouterHTMLreplace(/value=\w/g) value=清除file里字> |