jQuery增加千分符

<dl>
   <dt nc_type="no_spec">
      <span class="red">*</span>成本價:
   </dt>
   <dd nc_type="no_spec">
      <input type="text" class="text decimal" name="storeGoods.cost" dataType="double" id="cost"
         isrequired="true" />
   </dd>

</dl>

<script>
   $(".decimal").on("blur",function(money){
      var discount = $(this).val();
      var total;
      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);
      }
    });
</script>

發佈了31 篇原創文章 · 獲贊 7 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章