zoukankan      html  css  js  c++  java
  • Form表单,textarea标签输入框 字数限制,和已输入字数的统计显示

    <script type="text/javascript">
    $(document).ready(function() {
        <%-- 页面进来时就调用 --%>
        setTitleLength();
      });

    function setTitleLength() {
    $this = $('#title');
    var length = $this.val().length;
    var lengthNum = 40;//设置限制的字数
    //超过指定字数便截取
    if (length > lengthNum) {
    var text = $this.val().substring(0, lengthNum);
    $this.val(text);
    $('#info_limit').text(lengthNum);
    } else {
    $('#info_limit').text(length);
    }
    }
    </script>
    <body>
    <div class="control-group">
    <label class="control-label">标题:</label>
    <div class="controls">
        <%-- 添加事件调用 --%>
    <form:textarea id="title" path="title" htmlEscape="false" rows="3" class="input-xxlarge required" onkeyup="setTitleLength();"/>
    <span class="help-inline"><font color="red">*</font> </span>
    </div>
    <div class="controls">
    <font color=#666666>限40个字 已输入 <font color="#CC0000"><span id="info_limit">0</span></font> 个字</font>
    </div>
    </div>
    </body>


  • 相关阅读:
    401. Binary Watch
    46. Permutations
    61. Rotate List
    142. Linked List Cycle II
    86. Partition List
    234. Palindrome Linked List
    19. Remove Nth Node From End of List
    141. Linked List Cycle
    524. Longest Word in Dictionary through Deleting
    android ListView详解
  • 原文地址:https://www.cnblogs.com/lendar/p/10243282.html
Copyright © 2011-2022 走看看