只能輸入和粘貼漢字
<input onkeyup =“value = value.replace(/ [^ \ u4E00- \ u9FA5] / g珠月,'')”onbeforepaste =“clipboardData.setData('text'胜臊,clipboardData.getData ').replace(/ [^ \ u4E00- \ u9FA5] /克,''))“> <BR/>
只能輸入和粘貼數(shù)字
<input onkeyup =“this.value = this.value.replace(/ \ D / g常潮,'')”onafterpaste =“this.value = this.value.replace(/ \ D / g岔留,'')”/> <BR/>
數(shù)字腳本
<input onkeyup =“if(/ \ D / .test(this.value)){alert('只能輸入數(shù)字'); this.value ='';}”>
只能輸入數(shù)字和中文
<input onkeyup =“value = value.replace(/ [\ W] / g龄减,'')”onbeforepaste =“clipboardData.setData('text'违崇,clipboardData.getData('text')。replace(/ \ d] / g嗤谚,''))“>
簡易禁止輸入漢字
<input style =”ime-mode:disabled“>輸入法不轉(zhuǎn)換鳄橘,但可粘貼上
者
輸入數(shù)字和小數(shù)點
<輸入的onkeyup = “值= value.replace(/ [^ \ D {1瘫怜,} \ \ D {1暗挑,} |烹看。\ D {1陕习,}] /克, '')”/> <BR/>
只能數(shù)字和“ - ”赖晶,例如在輸入時間的時候可以用到
<input onkeyup =“value = value.replace(/ [^ \ w&=] | _ / ig律适,'')”onblur =“value = value.replace(/ [^ \ w& - ] | _ / ig,'' )“/>
JS控制輸入輸入字符限制ENTER鍵可以讓光標(biāo)移到下一個輸入框
代碼如下:
<input onkeydown =“if(event.keyCode == 13)event.keyCode = 9”>只能是中文
<input onkeyup =“value = value.replace(/ [ - ?] / g遏插,'')”onkeydown = “if(event.keyCode == 13)event.keyCode = 9”>屏蔽輸入法<input style =“ime-mode:disabled”onkeydown =“if(event.keyCode == 13)event.keyCode = 9”>只能輸入英文和數(shù)字
<input onkeyup =“value = value.replace(/ [/ W] / g捂贿,'')”onbeforepaste =“clipboardData.setData('text',clipboardData.getData('text' (/ [^ / d] / g胳嘲,''))“onkeydown =”if(event.keyCode == 13)event.keyCode = 9“>只能是數(shù)字
<input onkeyup =”value = value.replace(/ [^ / d] / g厂僧,'')“onbeforepaste =”clipboardData.setData('text',clipboardData.getData('text')了牛。replace(/ [^ / d] / g颜屠,''))“>
只能顯示辰妙,不能修改
代碼如下:
<input readonly value =“只能顯示,不能修改”>只能輸數(shù)字甫窟,判斷按鍵的值
<script language = javascript>
function onlyNum()
{
if(C芑搿((event.keyCode> = 48 && event.keyCode <= 57 )||(event.keyCode> = 96 && event.keyCode <= 105)||(event.keyCode == 8)))
event.returnValue = false;
}
</ script>
<input onkeydown =“onlyNum();”>
文本框只能輸入數(shù)字代碼(小數(shù)點也不能輸入)
<input onkeyup =“this.value = this.value.replace(// D / g,'')”onafterpaste =“this.value = this.value.replace (// D /克粗井, '')“>
只能輸入數(shù)字肴掷,能輸小數(shù)點。
on(isNaN(value))execCommand('undo')onafterpaste =“if(isNaN(value))execCommand('undo')”>
<input name = txt1 onchange =“if(// D /.test(this.value)){警報( '只能輸入數(shù)字'); THIS.VALUE = '';}“>
數(shù)字和小數(shù)點方法二
代碼如下:
<input type = text t_value =“”o_value =“”onkeptress =“if(背传!this.value.match(/ ^ [/ + / - )呆瞻?/ d *?/径玖。痴脾?/ d *?$ /)) .value = this.t_value; else this.t_value = this.value; if(this.value.match(/ ^(梳星?:[/ + / - )赞赖?/ d +(?:/./ d +)冤灾? /))this.o_value=this.value“onkeyup =”if(前域!this.value.match(/ ^ [/ + / - )?/ d *韵吨?/匿垄。?/ d *归粉?$ /))this.value = this.t_value; else this.t_value = this.value; if(this.value.match(/ ^(椿疗?:[/ + / - )?/ d +(糠悼?:/./ d +)届榄?)?$ /) )this.o_value = this.value“onblur =”if(倔喂!this.value.match(/ ^(铝条?:[/ + / - ]?/ d +(席噩?:/./ d +)班缰?| /./ d * ?)$ /))THIS.VALUE = this.o_value;否則{如果(this.value.match(/^/./ D + $ /))THIS.VALUE = 0 + THIS.VALUE;若(THIS.VALUE .match(/^/.$/))THIS.VALUE = 0; this.o_value = THIS.VALUE}“>
只能輸入字母和漢字
<input onkeyup =“value = value.replace(/ [/ d] / g班挖,'')”onbeforepaste =“clipboardData.setData('text'鲁捏,clipboardData.getData('text' (/ [/ d] / g芯砸,''))“maxlength = 10 name =”Numbers“>
只能輸入中文字母和數(shù)字萧芙,不能輸入中文
<input onkeyup =”value = value.replace(/ [^ / w /.//]/ ig给梅,'')“>
只能輸入數(shù)字和英文
<font color =”Red“> chun </ font>
<input onKeyUp =“value = value.replace(/ [^ / d | chun] / g,'')”>
小數(shù)點后只能有最多兩位(數(shù)字双揪,中文都可輸入)动羽,不能輸入字母和運算符號:<input onKeyPress =“if((event.keyCode <48 || event.keyCode> 57)&& event.keyCode! = 46 || //./d/d$/.test(value))event.returnValue=false">8渔期。小數(shù)點后只能有最多兩位(數(shù)字运吓,字母,中文都可輸入)疯趟,可以輸入運算符號:
<input onkeyup =“this.value = this.value.replace(/ ^(/ - )(/ d +)/拘哨。(/ d / d)。 $ /信峻,'$ 1 $ 2. $ 3')”>
只能是數(shù)字和小數(shù)點和加減乘際
只能輸入數(shù)字倦青,小數(shù)點,負(fù)數(shù)
代碼如下:
<input name =“input”type =“text”onkeyup =“JHshNumberText(this)”id =“title”>
<script language =“javascript”type =“text / javascript”> function JHshNumberText(a)
{
var fa = “”;
if(a.value.substring(0,1)==“ - ”)
fa =“ - ”;
var str =(a.value.replace(/ [^ 0-9盹舞。] / g产镐,''))。replace(/ [踢步。] [0-9] * [癣亚。] /,'获印。');
if(str.substring(0,1)==“述雾。”)
str =“0”+ str;
a.value中= FA + STR;
}
</ script>
取消按鈕按下時的虛線框兼丰,在輸入里添加屬性值hideFocus或者HideFocus = true
<input type =“submit”value =“提交”hidefocus =“true”/>
只讀文本框內(nèi)容绰咽,在輸入里添加屬性值readonly
<input type =“text”readonly />
防止退后清空的TEXT文檔(可把樣式內(nèi)容做做為引引)
<input type =“text”style =“behavior:url(#default#savehistory); “ />
ENTER鍵可以讓光標(biāo)移到下一個輸入框
<input type =“text”onkeydown =“if(event.keyCode == 13)event.keyCode = 9”/>
只能為中文(有閃動)
<輸入type =“text”onkeyup =“value = value.replace(/ [ - ?] / g,'')”onkeydown =“if(event.keyCode == 13)event.keyCode = 9”/>
只能為數(shù)字(有閃動)
<input type =“text”onkeyup =“value = value.replace(/ [^ / d] / g地粪,''
<input type =“text”style =“ime-mode:disabled”onkeydown =“if(event.keyCode == 13)event.keyCode = 9”onkeypress =“if((event.keyCode <48 || event.keyCode >有效
閃爍)
<input type =“text”onkeyup =“value = value.replace(/ [/ W] / g取募,'') “onbeforepaste =”clipboardData.setData('text',clipboardData.getData('text')蟆技。replace(/ [^ / d] / g玩敏,''))“/>
屏蔽輸入法
<input type =”text“name =“url”style =“ime-mode:disabled”onkeydown =“if(event.keyCode == 13)event.keyCode = 9”/>
只能輸入數(shù)字,小數(shù)點质礼,減號( - )字符(無閃動)
<input onkeypress =“if(event.keyCode旺聚!= 46 && event.keyCode!= 45 &&(event.keyCode <48 || event眶蕉。 keyCode> 57))event.returnValue = false“/>
只能輸入兩位小數(shù)砰粹,三位小數(shù)(有閃動)
<input type =“text”maxlength =“9”onkeyup =“if(value.match(/ ^ / d {3} $ /))value = value.replace(value,parseInt(value / 10)); value = value.replace(//./ d * /造挽。/ g碱璃,'弄痹。')“onkeypress =”if((event.keyCode <48 || event.keyCode> 57)&& event.keyCode!= 46 && event.keyCode 嵌器!= 45 || value.match(/ ^ / d {3} $ /)|| //./d{3}$/.test(value)){event.returnValue = false}“/>
輸入輸入框的各種樣式
輸入框景背景透明:
<input style =“background:transparent; border:1px solid #ffffff”>
鼠標(biāo)劃過輸入框肛真,輸入框背景色變色:
<INPUT value =“Type here”NAME =“user_pass”TYPE =“text”SIZE =“29”onmouseover =“this.style.borderColor ='black' style.backgroundColor ='plum'“
style =”width:106; height:21“
onmouseout =”this.style.borderColor ='black'; this.style.backgroundColor ='#ffffff'“style =”border-width: 1px的;邊框顏色=黑色“>
輸入字時輸入框邊框閃爍(邊框為小方式):
<script Language =“JavaScript”>
function borderColor(){
if(self ['oText']。style.borderColor =='red'){
self [ oText']爽航。style.borderColor ='yellow';
} else {
self ['oText']蚓让。style.borderColor ='red';
}
oTime = setTimeout('borderColor()',400);
}
</ script>
<input type =“text”id =“oText”style =“border:5px dotted red; color:red”onfocus =“borderColor(this);” 的onblur = “clearTimeout(oTime);”>
輸入字時輸入框邊框閃爍(邊框為虛線):
<style>
#oText {border:1px dotted#ff0000; ryo:expression(onfocus = function light(){with(document.all.oText){style.borderColor = (style.borderColor == “#ffee00” “#FF0000”: “#ffee00”讥珍?);計時器= setTimeout的(光历极,500);}},的onblur =函數(shù)(){this.style.borderColor = “#FF0000” ; clearTimeout(定時器)})};
</ style>
<input type =“text”id =“oText”>
自動橫向廷伸的輸入框:
<input type =“text”style =“huerreson:expression(this.width = this.scrollWidth)”value =“abcdefghijk”>
自動向下伸展的文本框:
<textarea name =“content”rows =“6”cols =“80”onpropertychange =“if(this.scrollHeight> 80)this.style.posHeight = this.scrollHeight + 5”>輸入幾個回車試試</ textarea>的
只有下劃線的文本框:
<input style =“border:0; border-bottom:1 solid black; background;
軟件序列號式的輸入框:
<script for =“T”event =“onkeyup”>
if(value.length == 3)document.all [event.srcElement.sourceIndex + 1] .select();
</ script>
<input name =“T”size =“5”maxlength =“3”> - <input name =“T”size =“5”maxlength =“3”> - <input name =“T” =“5”maxlength =“3”> - <input name =“T”size =“5”maxlength =“3”> - <input name =“T”size =“5”maxlength =“3”> - 輸入名稱=“T7”size =“5”maxlength =“3”>
軟件序列號的輸入框(完整版):
<script for =“T”event =“onkeyup”> if(value.length == maxLength)document.all [event.srcElement.sourceIndex + 1] .focus() ; </ script>
<script for =“T”event =“onfocus”> select(); </ script>
<script for =“Submit”event =“onclick”>
var sn = new Array();
for(i = 0; i <T.length; i ++)
sn = T.value;
警報(sn.join( “ - ”));
</ script>
<input name =“T”size =“5”maxlength =“3”> - <input name =“T”size =“5”maxlength =“3”> - <input name =“T” =“5”maxlength =“3”> - <input name =“T”size =“5”maxlength =“3”> - <