前两天在做一个UserStory的时候,其中一个Task是限制TextArea的最大输入字数.
在jsp中虽用maxLength限制了,但是感觉不是很好.最后在js中,进行了相关处理.
/*to limit the TextArea max length */
function checkLength(obj,maxlength){
if(obj.value.length > maxlength){
obj.value = obj.value.substring(0,maxlength);
}
}
在TextArea的地方直接调用如下代码即可
onpropertychange="checkLength(this,500);"
οninput="checkLength(this,500);"
这样就ok了....