How to auto format textbox inputs

后端 未结 4 1450
野性不改
野性不改 2020-12-21 23:36

   
      
   <         


        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-22 00:08

    user2897690 had the right idea but it didn't accept Numpad numbers. So took their javascript and modified it to work.

    Here is my interpretation of their code with the added feature.

    $("input[name='birthdate']:first").keyup(function(e){
        var chars = [48,49,50,51,52,53,54,55,56,57,96,97,98,99,100,101,102,103,104,105];
        var key=chars.indexOf(e.keyCode);
        console.log(key);
        if(key==-1)$(this).val($(this).val().substr(0,$(this).val().length-1));
        var value=$(this).val();
        if(value.length==2||value.length==5)$(this).val($(this).val()+'/');
    });
    

提交回复
热议问题