<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>限制文件字数字</title>
</head>
<body>
<span class="span">备注信息</br><span id="stay" style="display: none"> 您还可以输入:<span id="txtCount"></span>个字符的描述信息</span></span>
         </br><input id="Remark_information" name="Remark_information" type="text">

         <script>
    var lim=new limit();
    lim.txtNote=document.getElementById("Remark_information");
    lim.txtLimit=document.getElementById("txtCount");
    lim.limitCount=80;
    lim.init();
    function limit(){
        var txtNote;//文本框
        var txtLimit;//提示字数的input
        var limitCount;//限制的字数
        var txtlength;//到达限制时,字符串的长度
        this.init=function(){
            txtNote=this.txtNote;
            txtLimit=this.txtLimit;
            limitCount=this.limitCount;
            txtNote.oninput=function(){wordsLimit()};txtNote.oninput=function(){wordsLimit()};
            txtLimit.innerText=limitCount;
        };
        function wordsLimit(){
            var noteCount=txtNote.value.length;
            var InPut=document.getElementById("Remark_information").value.length;
            if(InPut<1){
                document.getElementById("stay").style.display="none";
                return
            }
            if(InPut>=1){
                document.getElementById("stay").style.display="inline";
                document.getElementById("stay").style.color="green";
            }
            if(InPut>70){
                document.getElementById("stay").style.color="red";
            }
            if(noteCount>limitCount){
                txtNote.value=txtNote.value.substring(0,limitCount);
                txtLimit.innerText=0;
            }else{
                txtLimit.innerText=limitCount-noteCount;
            }
            txtlength=txtNote.value.length;//记录每次输入后的长度
        }
    }
</script>
</body>

来自:http://www.cnblogs.com/zhujiasheng/p/6113983.html

  

JS 限制input框的输入字数,并提示可输入字数的更多相关文章

  1. js控制input框输入数字时,累计求和

    input框输入数字时,自动开始计算累加 <div class="form-group"> <label for="inputPassword3&quo ...

  2. js 动态控制 input 框 的只读属性

    需求: 当下拉框的值为06即Voucher时, 文本框才可输入, 其他情况均为置灰不可录入状态. 问题: 设置input框的只读属性写成了readonly="true" 尼玛,坑死 ...

  3. php页面输出时,js设置input框的选中值

    /* 设置表单的值 */ function setValue(name, value) { var first = name.substr(0, 1), input, i = 0, val; if ( ...

  4. js控制 input框中输入数字时,累计求和

    $('.cc input').bind('input propertychange', function(){ var total = 0; $("input").each(fun ...

  5. js控制input框只能输入数字和一位小数点和小数点后面两位小数

    <script language="JavaScript" type="text/javascript"> function clearNoNum( ...

  6. Js限制Input框只能输入数字

    <input type="text" onkeyup="value=value.replace(/[^\d]/g,'')" /> <input ...

  7. js复制input 框中的值

    function copy(){ var Url2=document.getElementById("copyValue"); Url2.select(); document.ex ...

  8. js对input框的可编辑属性设置

    添加disabled属性 $('#areaSelect').attr("disabled",true); $('#areaSelect').attr("disabled& ...

  9. 关于input框仿百度/google自动提示的方法

    引入jquery-autocomplete文件 链接:https://pan.baidu.com/s/1hW0XBYH8ZgJgMSY1Ce6Pig 密码:tv5b $(function() { $( ...

随机推荐

  1. 解决strip: Unable to recognise the format of the input file问题

    前言   在编译xilinx的uboot的时候出现了一个问题,始终报错:“strip: Unable to recognise the format of the input file `gen_et ...

  2. 创建一个dynamics CRM workflow (五) - Deploy Custom Workflows

    我们打开plugin registeration tool. 注册一个新的assembly. custom workflow 和 plugin注册的方法还有些不同. 这一步custom workflo ...

  3. 点击之后连接qq

    <a class=" "   style=""  href="http://wpa.qq.com/msgrd?v=3&uin=40482 ...

  4. 远程连接windows出现身份验证错误,提示"由于CredSSP加密Oracle修正"解决方案

    本机操作系统(OS版本:10.0.17134) 远程计算机操作系统(OS版本:6.3.9600) 远程连接的时候报错“出现身份验证错误,要求的函数不受支持.远程计算机:xxx 这可能是由于CredSS ...

  5. poj 3669 bfs(这道题隐藏着一个大坑)

    题意 在x,y坐标系,有流星会落下来,给出每颗流星落下来的坐标和时间,问你能否从(0,0)这个点到一个安全的位置.所谓的安全位置就是不会有流星落下的位置. 题解: 广搜,但是这里有一个深坑,就是搜索的 ...

  6. Edit Distance FZU-1434

    题目大意: 给你两个字符串A,B,和以下三种操作: 1.删除一个字符 2.插入一个字符 3.把一个字符改变成另一个字符 求使A变成B所需要的最少的操作: 我刚开始的思路是以为求出最长公共子序列,然后对 ...

  7. 2、Ansible配置文件详解

    0.配置文件 两个核心文件:ansible.cfg和hosts文件,默认都存放在/etc/ansible目录下. ansible.cfg:主要设置一些ansible初始化的信息,比如日志存放路径.模块 ...

  8. mplayer 在线播放错误

    CPU: ARM Playing rtsp://admin:12345@192.168.1.198/mpeg4/main/ch01/av_stream.Connecting to server 192 ...

  9. 【hiho一下 第九周】 状态压缩·二

    [题目链接]:http://hihocoder.com/problemset/problem/1048 [题意] [题解] 按从左到右然后从上到下的顺序; 依次枚举每个格子是竖条还是横条; 然后在搜索 ...

  10. C++ decltype类型说明符

    本系列文章由 @yhl_leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/50865552 1 基本语法 declt ...