1.每隔4位数字后加","号。

<input type='text' >

  

window.onload=function(){
  document.getElementById("test").onkeyup=function(){
      var regex=new RegExp(/\d/);
          if(!regex.test(this.value)){
           this.style.border="1px dashed red";
          }else{
            this.style.border="1px solid black";
            this.value=this.value.replace(/(\d{4})(?=\d)/,"$1,");
        }  
    }  
}            

2.将空格替换为‘,’和‘“,”’

    var showT=document.getElementById('showT');
    function addcomma(){
        var textAreaV=document.getElementById('textArea').value;
        showT.innerHTML=textAreaV.replace(/\s/g,",");
    }
    function addquo(){
        var textAreaV=document.getElementById('textArea').value;
        showT.innerHTML=textAreaV.replace(/\s/g,"','");
    }

  

相关文章:

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