文本框只能输入数字的js代码
发布:onlinerun | 发布时间: 2008年10月22日文本框只能输入数字的js代码提供给大家两种方案
第一种:
<input name="paixu" type="text" value="0" size=6 maxlength="6" onkeyup="value=value.replace(/[^\d]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))">
第二种:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<SCRIPT LANGUAGE="JavaScript">
function numericCheck(){
nr1=document.myform.content.value;
flg=0;
str="";
spc=""
arw="";
for (var i=0;i<nr1.length;i++){
cmp=".0123456789"
tst=nr1.substring(i,i+1)
if (cmp.indexOf(tst)<0){
flg++;
str+=" "+tst;
spc+=tst;
arw+="^";
}
else{arw+="_";}
}
if (flg!=0){
if (spc.indexOf(" ")>-1) {
str+="和空格";
}
alert("这里只接受数字,发现"
+flg+"个不可接受的字符:\n"+str);
return false;
}
}
</SCRIPT>
<form name="myform" method="post" enctype="text/plain" onsubmit="return numericCheck()" action="">
<INPUT TYPE="text" name="content">
<INPUT TYPE="submit" NAME="submit" VALUE="递交">
</form>
</body>
</html>
- 相关文章:
asp ubound 和lbound的用法详解 (2008-10-17 9:23:13)
如何获得自然流量 (2008-10-6 14:52:39)
第三代搜索引擎发展趋势 (2008-10-6 13:57:21)
关于gb2312转utf出现乱码的解决方法 (2008-9-23 15:14:44)
ico图标在线生成 - 很经典实用的哦 (2008-9-8 21:15:27)
点击复制文章地址推荐给你的朋友的js实现代码 (2008-9-2 13:3:45)
很全的显示阴历(农历)日期的js代码 (2008-9-1 19:24:43)
js日期比较函数,js时间比较函数 (2008-9-1 11:2:20)
正则表达式基础知识(入门知识) (2008-8-27 10:33:8)
divcss javascript 实现新闻列表滑动切换的效果 (2008-8-24 18:0:40)
发表评论
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。





