首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

只好输入数字

2012-11-23 
只能输入数字htmlheadmeta http-equivcontent-Type contenttext/htmlcharsetgb2312titlej

只能输入数字

<html><head><meta http-equiv="content-Type" content="text/html;charset=gb2312"><title>js 只能输入数字和小数点</title><script language="JavaScript" type="text/javascript">function clearNoNum(obj){   obj.value = obj.value.replace(/[^\d.]/g,"");  //清除“数字”和“.”以外的字符   obj.value = obj.value.replace(/^\./g,"");  //验证第一个字符是数字而不是.   obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的.   obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");}</script></head><body>只能输入数字和小数点的文本框:<input name="input1" onkeyup="clearNoNum(this)"></body></html>
?

热点排行