描述,输123 =》123.0054456.22=》54,456.22及时显示。。
1 回答
MMMHUHU
TA贡献1834条经验 获得超8个赞
<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%" />
添加回答
举报
0/150
提交
取消