$(function(){ $(".decimal").on("blur",function(money){ var discount = $(this).val(); var total; if(discount<=0){ alert("商品价格不能小于0!") }else if(discount!==''&&!isNaN(discount)){ total = parseFloat(discount); total = total.toFixed(2) + ""; var re=/(\d{1,3})(?=(\d{3})+(?:$|\.))/g; var n=total.replace(re,"$1,"); return $(this).val(n); }else{ alert("请输入正确的价格!"); return false; } });