前端常见问题收录
- react阻止冒泡事件 https://zhuanlan.zhihu.com/p/26742034/
- 需求:把数字转换成千位用,分隔的字符串,并保留两个小数点
var a = 123456.789; //1
a.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,');
//2
'111111.22222'.replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,');
//3
var qfw=(num)=>num.split('.')[0].replace(/(\d)(?=(?:\d{3})+$)/g,'$1,')+(num.split('.')[1]?'.'+num.split('.')[1]:'');