标签:
<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>
标签:
原文地址:http://www.cnblogs.com/shaoyang/p/5198936.html