JS自动格式化输入的数字千位分隔符
本帖最后由 sherlockhomles 于 2014-10-22 09:21 编辑<script>
function cc(s){
if(/[^0-9\.]/.test(s)) return "invalid value";
s=s.replace(/^(\d*)$/,"$1.");
s=(s+"00").replace(/(\d*\.\d\d)\d*/,"$1");
s=s.replace(".",",");
var re=/(\d)(\d{3},)/;
while(re.test(s))
s=s.replace(re,"$1,$2");
s=s.replace(/,(\d\d)$/,".$1");
return "¥" + s.replace(/^\./,"0.")
}
</script
6666666666666666666
UR银盾http://www.uryindun.com
UR银盾钢化膜http://www.aiyanm.com
static/image/common/sigline.gif
看帖是心情,回帖是道德
UR银盾http://www.uryindun.com
UR银盾钢化膜http://www.aiyanm.com 看了,感觉不错,谢谢您提供
static/image/common/sigline.gif
淘客机器人、淘客返利机器人、淘宝客机器人 联系客服QQ:4000017854
页:
[1]