开发者

mask and jQuery text box length

开发者 https://www.devze.com 2023-04-12 20:16 出处:网络
I have a jQuery which uses mask function and on keyup event I want to enter 000 when user type 0 otherwise keep user input. But this code breaks when user enters value with 0 like 80, it replaces 0 wi

I have a jQuery which uses mask function and on keyup event I want to enter 000 when user type 0 otherwise keep user input. But this code breaks when user enters value with 0 like 80, it replaces 0 with 000, so I need to use length function to prevent it, but it seems to break. Here is code:

$(document).ready(function(){
          $('#test').mask("999");
          $('#test').live('keyup', function(event){
                       if ((event.keyCode == 48) || (event.keyCode == 96)){                    $('#test').unmask;
                   var rtest = $('#test').val().length;
                 //  alert(rtest);
                   $('#test').mask("999");
                   if(rtest<=1){
                  $('#test').val("000");
                  }
 开发者_运维知识库              }

       });
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号