思路,比一定就是限制死,可以给提示
例如:
<script>
//多行文本输入框剩余字数计算
function checkMaxInput(obj, maxLen) {
if (obj == null || obj == undefined || obj == "") {
return;
}
if (maxLen == null || maxLen == undefined || maxLen == "") {
maxLen = 200;
}
var strResult;
var $obj = $(obj);
var newid = $obj.attr("id") + 'msg';
if (obj.value.length > maxLen) { //如果输入的字数超过了限制
obj.value = obj.value.substring(0, maxLen); //就去掉多余的字
strResult = '<span id="' + newid + '" class=\'Max_msg\' ><br/>剩(' + (maxLen - obj.value.length) + ')字</span>'; //计算并显示剩余字数
}
else {
strResult = '<span id="' + newid + '" class=\'Max_msg\' ><br/>剩(' + (maxLen - obj.value.length) + ')字</span>'; //计算并显示剩余字数
}
var $msg = $("#" + newid);
if ($msg.length == 0) {
$obj.after(strResult);
}
else {
$msg.html(strResult);
}
}
//清空剩除字数提醒信息
function resetMaxmsg() {
$("span.Max_msg").remove();
}
$Dialog().date($('#milepost_data'),function(){
var fdate = $("#milepost_data").val();
var _tdate = addDate(fdate,'365');
var tdate = _tdate.getFullYear()+"-"+(_tdate.getMonth()+1);
$("#vc_tdate").val(tdate);
});
</script>
<div class="contentInfo">
<label for="project_desc" style="margin-left:12px">项目目标描述:</label>
<textarea type="text" id="project_desc" name="project_desc" style="width:550px;height:90px" οnkeydοwn="checkMaxInput(this,200)"
οnkeyup="checkMaxInput(this,200)" οnfοcus="checkMaxInput(this,200)" οnblur="checkMaxInput(this,200);resetMaxmsg()" class="easyui-validatebox" (字数提示必须有这几个属性)
data-options="required:false" data-options="required:true"(必填) ></textarea>
<span style="color:red;">必须大于50字</span>红色给提示,一般跟在<input>后面
</div>