标签:
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 })
标签:
原文地址:http://www.cnblogs.com/kellie/p/5013514.html