numCk

来源:互联网 发布:手机淘宝网试衣间在哪 编辑:程序博客网 时间:2024/06/07 06:48
<!DOCTYPE html>
<html>
<body>








     
    <script language="JavaScript" type="text/javascript">    
    function clearNoNum(obj){
      obj.value = obj.value.replace(/^\./g,""); //必须保证第一个为数字而不是.   
      obj.value = obj.value.replace(/[^\d.]/g,"");  //清除“数字”和“.”以外的字符     
      obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的     
      obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");    
      obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d\d\d).*$/,'$1$2.$3');//只能輸入4个小数  
      








   
      if(obj.value.indexOf(".")< 0 && obj.value !=""){//以上已???,此?控制的是如果没有小数点,首位不能?出現類似于 01、02的金額    
       obj.value= parseFloat(obj.value);    
      } 












  
    }    
 












</script>
<style>
body {
    background-color: lightblue;
}


h1 {
    color: white;
    text-align: center;
}


p {
    font-family: verdana;
    font-size: 20px;
}
</style>




<h1><input type="text" name="je" onkeyup="clearNoNum(this)" />元</h1> 
</body>
</html>
0 0
原创粉丝点击