$(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; } });
判断输入为正数并且增加千分符
最新推荐文章于 2021-09-01 20:31:17 发布
本文介绍了一种使用JavaScript实现的商品价格格式化处理方法。当用户输入商品价格后失去焦点时,该方法会验证并格式化输入的价格,确保其正确性和易读性。如果输入的价格小于零或格式不正确,将提示用户进行修正。
607

被折叠的 条评论
为什么被折叠?



