zoukankan      html  css  js  c++  java
  • 【表单】文本域字符数判断

    文本域字符数判断 by 渔人码头
    http://www.css88.com/archives/2027

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>
    
    <body>
    <div id="tip" style="color:#588905;">你还能输入<em>140</em>个字!</div>
    <form action="" method="post">
        <textarea id="textArea" name="textArea" cols="50" rows="10"></textarea><br />
        <input id="button" name="button" type="submit" value="提交" />
    </form>
    <script>
    document.getElementById("textArea").focus();
    var chackTextarea = function (obj, num, objTip) {
        setInterval(function () {
            // \x00-\xff所有拉丁字符 ^除了 g全局匹配 用**替换掉其中的汉字“abc汉子”替换成“abc****”
            var newvalue = obj.value.replace(/[^\x00-\xff]/g, "**");        
            if (newvalue.length >= 0) {
                if (newvalue.length > num) {
                    objTip.innerHTML = "已超出<em>" + parseInt((newvalue.length - num)/2) + "</em>个字!";
                    objTip.style.color = "#f00";
                    document.getElementById("button").disabled = "disabled";
                } else {
                    objTip.innerHTML = "你还能输入<em>" + parseInt((num - newvalue.length)/2) + "</em>个字!";
                    objTip.style.color = "#588905";
                    document.getElementById("button").disabled = "";
                }
            } else {
                document.getElementById("button").disabled = "disabled";
            }
        }, 100);
    }
    chackTextarea(document.getElementById("textArea"), 280, document.getElementById("tip"));
    </script>
    </body>
    </html>
  • 相关阅读:
    mysql权限
    Win7_64位使用Mysql Odbc
    二叉树的遍历
    Notepad++的使用
    mysql与mysqld
    Mysql 聚集函数和分组
    Linux 目录
    Linux 倒引号、单引号、双引号
    openkm安装过程
    rhel 7 设置默认运行级别为图形
  • 原文地址:https://www.cnblogs.com/jzm17173/p/2575153.html
Copyright © 2011-2022 走看看