• 文本显示输入字数


    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    <style type="text/css">
    .progress{
      1px;
     height: 14px;
     color: white;
     font-size: 12px;
        overflow: hidden;
     background-color: navy;
     padding-left: 5px;
    }
    </style>
    <script type="text/JavaScript">
    function textCounter(field,counter,maxlimit,linecounter) {
     // text width//
     var fieldWidth =  parseInt(field.offsetWidth);
     var charcnt = field.value.length;        
     // trim the extra text
     if (charcnt > maxlimit) { 
      field.value = field.value.substring(0, maxlimit);
     }
     else { 
     // progress bar percentage
     var percentage = parseInt(100 - (( maxlimit - charcnt) * 100)/maxlimit) ;
     document.getElementById(counter).style.width =  parseInt((fieldWidth*percentage)/100)+"px";
     document.getElementById(counter).innerHTML="已输: "+percentage+"%"
     // color correction on style from CCFFF -> CC0000
     setcolor(document.getElementById(counter),percentage,"background-color");
     }
    }
    function setcolor(obj,percentage,prop){
     obj.style[prop] = "rgb(80%,"+(100-percentage)+"%,"+(100-percentage)+"%)";
    }
    </script>
    <p>限制:120字节</P>
    <form>
    <textarea rows="5" cols="40" name="maxcharfield" id="maxcharfield" 
    onKeyDown="textCounter(this,'progressbar1',120)" 
    onKeyUp="textCounter(this,'progressbar1',120)"
    onPaste="textCounter(this,'progressbar1',120)" 
    onFocus="textCounter(this,'progressbar1',120)" ></textarea><br />
    <div id="progressbar1" class="progress"></div>
    <script>textCounter(document.getElementById("maxcharfield"),"progressbar1",120)</script>
    </form></font>

    限制:120字节


    欢迎访问阿里西西网页特效代码站,js.alixixi.com



  • 相关阅读:
    Selenium操作之滚动条
    IntelliJ IDEA代码编码区提示库源不匹配字节码解决办法
    自动化测试浅谈
    json-lib解析json之二维JSONArray
    Java 多态
    Java0基础教程——java的安装
    LAYUI弹出层详解
    ajax实现动态URL
    js serialize()
    TP5.1接入支付宝实现网页/APP支付完整请求回调流程(沙箱环境)
  • 原文地址:https://www.cnblogs.com/babyhhcsy/p/42dafab8344d943a6aa45792ec61f9cd.html
Copyright © 2020-2023  润新知