第一种很普通的方法:

<input type="text" id="waterAcount" onkeyup='checkNumAddSpace(this.value)'/>
function checkNumAddSpace(num){

 if(num.length == 4 || num.length == 9 || num.length ==14 || num.length ==19){

 $("waterAcount").value = num + " ";

 }

}

第二种方法,利用正则表达式:

<input type="text" id="waterAcount"/>
window.onload =function() {

            document.getElementById("waterAcount").onkeyup =function() {

                this.value =this.value.replace(/\s/g,'').replace(/(\d{4})(?=\d)/g,"$1 ");;

            };

        };

相关文章:

  • 2021-12-13
  • 2022-12-23
  • 2022-12-23
  • 2021-12-10
  • 2022-02-07
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案