JS TextArea文字列長制限コードセット 2659 ワード <br/><input type="text" id="b2"/> <br/><script type="text/javascript"> <br>textAreaLimit("t",{lastMsgLabel:"b2"}) <br>function textAreaLimit(area,op){ <br>var defaultOp = { <br>maxLength:10 // <br>, IsNumber:false // <br>, lastMsgLabel:null // Input <br>, msg:" {0} " <br>, errorMsg:" " <br>}; <br>var label; <br>if(typeof area == "string"){ <br>area = document.getElementById(area); <br>} <br>if(!area){ <br>return; <br>} <br>for(var i in op){ <br>defaultOp[i] = op[i]; <br>} <br>if(defaultOp.lastMsgLabel){ <br>if(typeof defaultOp.lastMsgLabel == "string"){ <br>label = document.getElementById(defaultOp.lastMsgLabel); <br>} <br>} <br>if(defaultOp.IsNumber){ <br>area.style.imeMode="Disabled";//IE <br>area.onkeydown = function(){ <br>return event.keyCode != 229; <br>} <br>} <br>area.onkeyup = function(){ <br>if(defaultOp.IsNumber){ <br>this.value = this.value.replace(/\D/g,"");//IE <br>} <br>if(this.value.length > defaultOp.maxLength){ <br>//------------------------------------------------------------------------------- <br>// ① <br>this.disabled = "disabled"; <br>this.value = this.value.slice(0,defaultOp.maxLength); <br>this.removeAttribute("disabled"); <br>this.focus(); <br>// ② <br>// <br>//alert(defaultOp.errorMsg); <br>//this.value = this.value.slice(0,defaultOp.maxLength); <br>//------------------------------------------------------------------------------- <br>} <br>if(label){ <br>label.value = defaultOp.msg.replace(/\{0\}/,defaultOp.maxLength -this.value.length); <br>} <br>} <br>} <br></script> <br/> <br/> <br/> </code></pre> <br/> + BUG 。 <br/> 。 <br/> , ②, ①。 <div class="clearfix"> <span id="art_bot" class="jbTestPos"/> </div> </div> </div> </div> 剣指OFFER----5-3-1、数字がソート配列に出現する回数(js実現)