表单的常用限制js代码

<!–限制只能输入中文–>
<h4>限制输入框只能输入中文</h4>
<input onkeyup=”value=value.replace(/[ -~]/g,”)” onkeydown=”if(event.keyCode==13)event.keyCode=9″>

<!–限制输入框只能输入英文和数字–>
<h4>限制输入框只能输入英文和数字</h4>
<input onkeyup=”value=value.replace(/[\W]/g,”)” onbeforepaste=”clipboardData.setData(‘text’,clipboardData.getData(‘text’).replace(/[^\d]/g,”))”>
<!–限制输入框只能输入数字(无闪动)–>
<h4>限制输入框只能输入数字(无闪动)</h4>
<input style=”ime-mode:disabled” onkeydown=”if(event.keyCode==13)event.keyCode=9″ onKeyPress=”if ((event.keyCode<48 || event.keyCode>57)) event.returnValue=false”>

<!–屏蔽输入法–>
<h4>屏蔽输入法</h4>
<input type=”text” name=”url” style=”ime-mode:disabled” onkeydown=”if(event.keyCode==13)event.keyCode=9″>

<!–只能输入 数字,小数点,减号(-) 字符–>
<h4>只能输入 数字,小数点,减号(-) 字符</h4>
<input onKeyPress=”if (event.keyCode!=46 && event.keyCode!=45 && (event.keyCode<48 || event.keyCode>57)) event.returnValue=false”>

<!–点击文本框去除默认值(仿163.com)–>
<h4>点击文本框去除默认值(仿163.com)</h4>
<style type=”text/css”>
input {color:#ccc;}
</style>
</head>
<body>

<input type=”text” value=”Input URL or Search String” />

<script type=”text/javascript”>
<!–
// 文本框点击状态控制(兼容)
var Ptr=document.getElementsByTagName(“input”);
for(var i=0;i<Ptr.length;i++) {
if(Ptr[i].type==”text”){
Ptr[i].onmouseover=function(){
this.style.color=”#0d4584″;
if (this.value==this.defaultValue){
this.value=”;
}
};
Ptr[i].onmouseout=function(){
this.style.color=””;
if (this.value==””) {
this.value=this.defaultValue;
}
};
}
}
//–>
</script>

<!–界面漂亮的表单–>
<h4>界面漂亮的表单</h4>
<table width=”279″ height=”133″ border=”0″ cellpadding=”0″ cellspacing=”0″>
<tr>
<td align=”left”><p>
<form name=”form1″ method=”post” action=””>
<input style=”color: #ff0000; background-color: #FFFFFF; border: #006699; border-style: dashed; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 1px; border-left-width: 0px” size=”41″><br>
<input style=”color: #ff0000; background-color: #FFFFFF; border: #006699; border-style: dashed; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 1px; border-left-width: 0px” size=”41″><br>
<input style=”color: #ff0000; background-color: #FFFFFF; border: #006699; border-style: dashed; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 1px; border-left-width: 0px” size=”41″><br>
<textarea name=”textarea” cols=”41″ style=”color: #ff0000; background-color: #FFFFFF; border: #006699; border-style: dashed; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px”></textarea size=”40″>
<br>

<input type=”submit” name=”Submit” value=” 确 认 ” style=”color: #ff0000; background-color: #ffffff; border: #006699; border-style: dashed; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px”>
<input type=”reset” name=”Submit2″ value=” 重 置 ” style=”color: #ff0000; background-color: #FFFFFF; border: #006699; border-style: dashed; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px”>
</form> <p>&nbsp;</p></td>
</tr>
</table>

 » 本站地址:http://www.gomoth.com
  • 您可能感兴趣的相关文章