源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

jQuery实现简易的输入框字数计数功能示例

  • 时间:2022-09-27 23:44 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:jQuery实现简易的输入框字数计数功能示例
本文实例讲述了jQuery实现简易的输入框字数计数功能。分享给大家供大家参考,具体如下: 运行效果图如下: [img]http://files.jb51.net/file_images/article/201701/2017116122052462.png?2017016122116[/img] 具体代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title></title>
  <script src="jquery-1.7.2.min.js"></script>
</head>
<body>
<div class="container">
  <input id="abc" value="编程素材网"><span id="wordCountShow"></span>
</div>
<script>
  $.fn.extend({
    wordCount: function (maxLength, wordWrapper) {
      var self = this;
      $(self).attr("maxlength", maxLength);
      showWordCount();
      $(this).on("input propertychange", showWordCount);
      function showWordCount() {
        curLength = $(self).val().length;
        var leaveCount = maxLength - curLength;
        wordWrapper.text(leaveCount + "/" + maxLength);
      }
    }
  })
  $(function () {
    $("#abc").wordCount(10, $("#wordCountShow"));
  })
</script>
</body>
</html>

[b]PS:这里再为大家提供几款带有字数统计功能的在线工具供大家参考使用:[/b] [b]在线字数统计工具: [/b][url=http://tools.jb51.net/code/zishutongji]http://tools.jb51.net/code/zishutongji[/url] [b]在线文本美化排版工具: [/b][url=http://tools.jb51.net/aideddesign/txt_paiban]http://tools.jb51.net/aideddesign/txt_paiban[/url] [b]在线自动排版与转换工具: [/b][url=http://tools.jb51.net/aideddesign/txt_beaut]http://tools.jb51.net/aideddesign/txt_beaut[/url] 更多关于jQuery相关内容感兴趣的读者可查看本站专题:《[url=http://www.1sucai.cn/Special/200.htm]jQuery常用插件及用法总结[/url]》、《[url=http://www.1sucai.cn/Special/451.htm]jQuery扩展技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/514.htm]jQuery切换特效与技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/628.htm]jQuery遍历算法与技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/430.htm]jQuery常见经典特效汇总[/url]》、《[url=http://www.1sucai.cn/Special/104.htm]jQuery动画与特效用法总结[/url]》及《[url=http://www.1sucai.cn/Special/75.htm]jquery选择器用法总结[/url]》 希望本文所述对大家jQuery程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部