MMMHUHU
javascript自动格式化金额,可包含小数 <script>
function formatter(o) {
var arr = o.value.split('.'), nl = arr[0].length;
var tmp = arr[0].replace(/(\d{3}(?!,))/g, '$1,').replace(/,$/g, '')
var ss = o.selectionStart + tmp.length - arr[0].length;
console.log(ss)
o.value = tmp + '.' + (arr[1] || '00').substring(0,2);
o.selectionStart=o.selectionEnd=ss
}
</script>
<input type="text" onkeypress="ss = this.selectionStart" oninput="formatter(this)" onpropertychange="formatter(this)" style="width:100%" />