JavaScript開発でテキストエリア(textarea)の文字数制限(maxlength)の処理方法

コード下記
var MaxLenCheck = function(){
var stmaxLen = 2048;
this.doKeyPress = function(element, event){
var maxLength = element.getAttribute(“maxLength");
maxLength = maxLength || stmaxLen;
if (maxLength !== “") {
if (element.value.length >= maxLength) {
if (window.event) {
window.event.returnValue = null;
}
else {
return false;
}
}
}
this.doOtherThing();
};
/**
* 貼り付け処理
*/
this.doPaste = function(element, event){
var maxLength = element.getAttribute(“maxLength");
maxLength = maxLength || stmaxLen;
if (maxLength !== “") {
var cfmt = window.clipboardData.getData(“Text");
var subStr = cfmt.substr(0, maxLength – element.value.length);
window.clipboardData.setData(“Text", subStr);
}
this.doOtherThing();
};
this.doOtherThing = function(){
// Client Programer implment this function
};
}

JavaScript

Posted by arkgame