zoukankan      html  css  js  c++  java
  • textarea还剩余字数统计

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8" />
    <title>textarea还剩余字数统计 - 懒人建站 http://www.51xuediannao.com/</title>
    <style type="text/css">
    body,a{ font-size: 14px; color: #555;;}
    .wordCount{ position:relative; 600px; }
    .wordCount textarea{ 100%; height: 100px;}
    .wordCount .wordwrap{ position:absolute; right: 6px; bottom: 6px;}
    .wordCount .word{ color: red; padding: 0 4px;;}
    </style>
    </head>
    <body>
    <div class="wordCount" id="wordCount">
    <textarea placeholder="textarea还剩余字数统计"></textarea>
    <span class="wordwrap"><var class="word">200</var>/200</span>
    </div>


    <span id="clock"></span>
    <script src="http://lib.sinaapp.com/js/jquery/1.10.2/jquery-1.10.2.min.js"></script>
    <script>
    $(function(){

    //先选出 textarea 和 统计字数 dom 节点
    var wordCount = $("#wordCount"),
    textArea = wordCount.find("textarea"),
    word = wordCount.find(".word");
    //调用
    statInputNum(textArea,word);

    });
    /*
    * 剩余字数统计
    * 注意 最大字数只需要在放数字的节点哪里直接写好即可 如:<var class="word">200</var>
    */
    function statInputNum(textArea,numItem) {
    var max = numItem.text(),
    curLength;
    textArea[0].setAttribute("maxlength", max);
    curLength = textArea.val().length;
    numItem.text(max - curLength);
    textArea.on('input propertychange', function () {
    numItem.text(max - $(this).val().length);
    });
    }
    </script>
    </body>
    </html>

  • 相关阅读:
    MySQL Date函数的正确用法
    CentOS tree命令详解
    VMware虚拟机的CentOS无法上网的解决方法
    CentOS安装emacs24.2命令
    【复杂】CentOS 6.4下PXE+Kickstart无人值守安装操作系统
    CentOS定位、查找文件的命令
    CentOS查找目录或文件
    CentOS安装Emacs文本编辑器
    centos6.5的软件安装,用户管理等
    CentOS安装OpenOffice
  • 原文地址:https://www.cnblogs.com/cxxjohnson/p/5071386.html
Copyright © 2011-2022 走看看