• 多个文本域字数限制


    <script>
    function getStringUTFLength(str) {
     var value = str.replace(/[u4e00-u9fa5]/g," ");
     //将汉字替换为两个空格
     return value.length;
    }
    function leftUTFString(str,len) {
     if(getStringUTFLength(str)<=len) {
      return str;
     }
     var value = str.substring(0,len);
     while(getStringUTFLength(value)>len) {
      value = value.substring(0,value.length-1);
     }
     return value;
    }
    function count(id) {
     var len=300;
     var value = $('textarea[resultid='+id+']').val();
     if(getStringUTFLength(value)>=len) {
      $('textarea[resultid='+id+']').val(leftUTFString(value,len));
     }
     $('input[resultid='+id+']').val(len-getStringUTFLength(value));
    }
    </script>

     <div class="content"><b><td>五、简答题</td></b></div><br><br>
              <c:forEach var="question" items="${testPaper.questions}">
              <c:if test="${'5' eq question.status }">
              <div class="content">
              <span style="color: #22536A;font-weight: bold;font-size: 16px;"> <%=i++ %>、<c:out value="${question.questionName }"/></span>
              <ul style="list-style: none;margin-left: 0px">
                             剩余可输入字数:<font color="red"><input resultid="${question.id }"  readonly type="text" size="3" id="result" value="300"></font>
              <li><textarea  id="${question.id }" resultid="${question.id }"  name="qId<c:out value="${question.id }"/>"  rows="10" cols="80" onkeypress="count(${question.id })" onkeyup="count(${question.id })" onblur="count(${question.id });" onChange="count(${question.id });"></textarea></li>
              </ul>
              </div>
              </c:if>
          </c:forEach>

  • 相关阅读:
    usaco contest
    chapter 2.getting started
    几种常见排序
    [usaco]Programming Contest Problem Types
    回溯实现组合问题
    第二章:循环结构程序设计
    第一章:程序设计入门
    第三章:数组和字符串
    数据库设计(一对一、一对多、多对多)
    linux与windows回车换行符的区别
  • 原文地址:https://www.cnblogs.com/shaoyang/p/5198936.html
Copyright © 2020-2023  润新知