1 <input type="number" placeholder="1.00元" name="get_price" id="get_price" max="1000">

 


 1 $("#get_money").keyup(function(){
 2      var money = $("#get_money").val();
 3      var re = /^(-)?(([1-9]{1}\d*)|([0]{1}))(\.(\d){1,2})?$/ ;
 4      if(!re.test(money)){
 5 
 6         if(money.indexOf(".")==1 && money.length==2){
 7 
 8         }else if(money.length ==5){
 9             $(this).val(money.substr(0, 4));
10 
11         }else if(money.substr(0, 2)!='0.'&& money.substr(0, 1)==0){
12 
13             $(this).val(money.substr(1, 2));
14 
15         }else if(money.length >3){
16 
17             $(this).val(parseFloat(money).toFixed(2));
18         }
19         
20      }
21   })

 



  

posted on 2015-12-02 17:00  kellie  阅读(101)  评论(0)    收藏  举报