input框限制輸入金額
阿新 • • 發佈:2022-03-05
HTML:
<input type="tel" class="capital mui-input-clear" value="0.00"> <div class="redbag_box4_son">¥0.00</div>JS:
$(document).ready(function(){ // 限制文字框只能輸入數字和小數點 var precapital; document.querySelector('.capital').addEventListener('focus', function() { if (this.value == '0.00') {this.value = this.value.replace(/^[\.]/, '').replace(/[^\d.]/g, ''); if (this.value.split(".").length - 1 > 1) {
參考連結:https://www.cnblogs.com/kousuke/p/perfect-input-for-money.html