只能輸入和粘貼漢字
<input onkeyup =“value = value.replace(/ [^ \ u4E00- \ u9FA5] / g,'')”onbeforepaste =“clipboardData.setData('text',clipboardData.getData ').replace(/ [^ \ u4E00- \ u9FA5] /克,''))“> <BR/>
只能輸入和粘貼數字
<input onkeyup =“this.value = this.value.replace(/ \ D / g,'')”onafterpaste =“this.value = this.value.replace(/ \ D / g,'')”/> <BR/>
數字腳本
<input onkeyup =“if(/ \ D / .test(this.value)){alert('只能輸入數字'); this.value ='';}”>
只能輸入數字和中文
<input onkeyup =“value = value.replace(/ [\ W] / g,'')”onbeforepaste =“clipboardData.setData('text',clipboardData.getData('text')。replace(/ \ d] / g,''))“>
簡易禁止輸入漢字
<input style =”ime-mode:disabled“>輸入法不轉換,但可粘貼上
者
輸入數字和小數點
<輸入的onkeyup = “值= value.replace(/ [^ \ D {1,} \ \ D {1,} |。\ D {1,}] /克, '')”/> <BR/>
只能數字和“ - ”,例如在輸入時間的時候可以用到
<input onkeyup =“value = value.replace(/ [^ \ w&=] | _ / ig,'')”onblur =“value = value.replace(/ [^ \ w& - ] | _ / ig,'' )“/>
JS控制輸入輸入字符限制ENTER鍵可以讓光標移到下一個輸入框
代碼如下:
<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”>只能輸入英文和數字
<input onkeyup =“value = value.replace(/ [/ W] / g,'')”onbeforepaste =“clipboardData.setData('text',clipboardData.getData('text' (/ [^ / d] / g,''))“onkeydown =”if(event.keyCode == 13)event.keyCode = 9“>只能是數字
<input onkeyup =”value = value.replace(/ [^ / d] / g,'')“onbeforepaste =”clipboardData.setData('text',clipboardData.getData('text')。replace(/ [^ / d] / g,''))“>
只能顯示,不能修改
代碼如下:
<input readonly value =“只能顯示,不能修改”>只能輸數字,判斷按鍵的值
<script language = javascript>
function onlyNum()
{
if(?。ǎ╡vent.keyCode> = 48 && event.keyCode <= 57 )||(event.keyCode> = 96 && event.keyCode <= 105)||(event.keyCode == 8)))
event.returnValue = false;
}
</ script>
<input onkeydown =“onlyNum();”>
文本框只能輸入數字代碼(小數點也不能輸入)
<input onkeyup =“this.value = this.value.replace(// D / g,'')”onafterpaste =“this.value = this.value.replace (// D /克, '')“>
只能輸入數字,能輸小數點。
on(isNaN(value))execCommand('undo')onafterpaste =“if(isNaN(value))execCommand('undo')”>
<input name = txt1 onchange =“if(// D /.test(this.value)){警報( '只能輸入數字'); THIS.VALUE = '';}“>
數字和小數點方法二
代碼如下:
<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“>
只能輸入中文字母和數字,不能輸入中文
<input onkeyup =”value = value.replace(/ [^ / w /.//]/ ig,'')“>
只能輸入數字和英文
<font color =”Red“> chun </ font>
<input onKeyUp =“value = value.replace(/ [^ / d | chun] / g,'')”>
小數點后只能有最多兩位(數字,中文都可輸入),不能輸入字母和運算符號:<input onKeyPress =“if((event.keyCode <48 || event.keyCode> 57)&& event.keyCode! = 46 || //./d/d$/.test(value))event.returnValue=false">8。小數點后只能有最多兩位(數字,字母,中文都可輸入),可以輸入運算符號:
<input onkeyup =“this.value = this.value.replace(/ ^(/ - )(/ d +)/。(/ d / d)。 $ /,'$ 1 $ 2. $ 3')”>
只能是數字和小數點和加減乘際
只能輸入數字,小數點,負數
代碼如下:
<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)==“?!保?br>
str =“0”+ str;
a.value中= FA + STR;
}
</ script>
取消按鈕按下時的虛線框,在輸入里添加屬性值hideFocus或者HideFocus = true
<input type =“submit”value =“提交”hidefocus =“true”/>
只讀文本框內容,在輸入里添加屬性值readonly
<input type =“text”readonly />
防止退后清空的TEXT文檔(可把樣式內容做做為引引)
<input type =“text”style =“behavior:url(#default#savehistory); “ />
ENTER鍵可以讓光標移到下一個輸入框
<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”/>
只能為數字(有閃動)
<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”/>
只能輸入數字,小數點,減號( - )字符(無閃動)
<input onkeypress =“if(event.keyCode!= 46 && event.keyCode!= 45 &&(event.keyCode <48 || event。 keyCode> 57))event.returnValue = false“/>
只能輸入兩位小數,三位小數(有閃動)
<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”>
鼠標劃過輸入框,輸入框背景色變色:
<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 =函數(){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”> - <