mask and jQuery text box length
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");
}
开发者_运维知识库 }
});
精彩评论