只能输入和粘贴汉字
<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(!((event.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)==“。”)
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”> - <