字符计数插件计算文本字段中 字符

  • 源码大小:6.36KB
  • 所需积分:1积分
  • 源码编号:19JP-3128
  • 浏览次数:618次
  • 最后更新:2023年05月08日
  • 所属栏目:表单
我要下载
加入收藏
本站默认解压密码:19jp.com 或 19jp_com

简介

一个小巧快速的jQuery字符计数器插件,可以计算文本字段中的字符数,并在用户键入时实时显示剩余/最大字符数

适用于限制帖子中字符数的社交媒体平台,或需要特定输入长度的网络表单。

如何使用它:

1.下载并在jQuery之后插入字符计数插件的缩小版。

  1. <script src="/path/to/cdn/jquery.slim.min.js"></script>
  2. <script src="/path/to/js/char-count.min.js"></script>

2.调用函数费用_计数在文本字段上。

  1. $('input, textarea').char_count({
  2. // options here
  3. });

3.设置允许插入的最大字符数。

  1. $('input, textarea').char_count({
  2. maxValue: 140,
  3. });

4.确定是否在计数器中显示最大值。

  1. $('input, textarea').char_count({
  2. showMaxValue: true,
  3. });

5.当文本字段失去焦点时,确定是否隐藏字符计数器。

  1. $('input, textarea').char_count({
  2. hideOnBlur: false,
  3. });

6.自定义字符计数器的背景颜色。

  1. $('input, textarea').char_count({
  2. background: "#34BC00",
  3. });

7.更改字符计数器的位置。

  1. $('input, textarea').char_count({
  2. position: "bottom",
  3. });

预览截图