<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>