<html>  
<head>  
<meta http-equiv="content-Type" content="text/html;charset=gb2312">  
<title>js 只能输入数字和小数点</title>  
<script language="
javascript" type="text/javascript">  
     function clearNoNum(obj)   
     {   
         //先把非数字的都替换掉,除了数字和.   
        objobj.value = obj.value.replace(/[^d.]/g,"");   
         //必须保证第一个为数字而不是.   
        objobj.value = obj.value.replace(/^./g,"");   
         //保证只有出现一个.而没有多个.   
        objobj.value = obj.value.replace(/.{2,}/g,".");   
         //保证.只出现一次,而不能出现两次以上   
        objobj.value = obj.value.replace(".","$#$").replace(/./g,"").replace("$#$",".");   
     }   
    </script>  
</head>  
<body>  
<!--把下面代码加到<body>与</body>之间-->  
只能输入数字和小数点的文本框:<input id="input1" onkeyup="clearNoNum(this)">  
</body>  
</html>