Not able to count characters using jQuery
I know I hav开发者_JS百科e a similar post, but it only answered part of my problem.
Her is my challenge to you: Can you make the alert display the correct number of characters? Even when you press backspace?
Here is the code:
jQuery('#input_Name').keydown(function(e) {
var count = $(this).val().length;
alert(count+1);
});
Hint: The ascii key for backspace is 8 ( if (e.keyCode != 8)
)
(I'm not able to get this right)
jQuery('#input_Name').keyup(function(e) {
var count = $(this).val().length;
alert(count)
});
精彩评论