//删除左右空格
String.prototype.trim = function() {
return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.lenB = function() {
return this.replace(/[^\x00-\xff]/g, "**").length;
} //一个汉字算2个字节
var maxl = 400 //总长
document.onkeyup = function() {
var s = document.getElementById("comment_deatal").value.lenB();
document.getElementById("charCount").innerHTML = s;
}
function checkTextLength() {
var length = document.forms[0].comment_deatal.value.trim().lenB();
if (length < 1) {
alert("对不起,请输入评论内容!");
return;
} else if (length > 400) {
alert("对不起,您输入的长度超过限制!");
return;
}
document.commentForm.action = "<%=webapp%>/comment.do?method=saveComment";
document.commentForm.submit();
}
实时提示输入字节数
最新推荐文章于 2025-01-25 08:00:00 发布