无法使用jQuery计算字符 [英] Not able to count characters using jQuery

查看:102
本文介绍了无法使用jQuery计算字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我也有类似的帖子,但是它只回答了部分问题.

I know I have 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?

这是代码:

jQuery('#input_Name').keydown(function(e) {
  var count = $(this).val().length;
  alert(count+1);
});

提示:退格键的ascii键是8(if (e.keyCode != 8))

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)
});

这篇关于无法使用jQuery计算字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆