Basically, I do not want the user to enter '0' (zero) as开发者_运维百科 the first character in a textbox which represents data with type of integer?
I would like to bind an event handler to handle this with jQuery.
Any experience?
Thanks,
You can replace the value with the integer value if you want:
$(".IntegerInput").val(function(i, v) {
return parseInt(v, 10);
});
This will parse the int and replace the value with it, removing any leading 0's.
Romuald made a god catch, for your specific case you'll need the radix argument on parseInt()
You could just simply replace it on the keyup like this:
$('#test').keyup(function() {
if ($(this).val() === '0')
{
$(this).val('');
}
});
you can use somthing like $('textbox').val().substr(0,1) != 0
;
Though it would be better if we knew what you would like accomplish
精彩评论