前两天在做一个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);"
oninput="checkLength(this,500);"
这样就ok了....
There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.