textarea 控制输入字符字节数(示例代码)

按字符数控制:

复制代码 代码如下:


<textarea 
             onkeyup="if(this.value.length>2000) this.value=this.value.substr(0,2000)"
             onkeydown="if(this.value.length>2000) this.value=this.value.substr(0,2000)"
             onblur="if(this.value.length>2000) this.value=this.value.substr(0,2000)"
             onpropertychange= "if(this.value.length>2000) this.value=this.value.substr(0,2000)"></textarea>


按字节数控制:

复制代码 代码如下:


<textarea cols="50" rows="5"
      onkeydown="key1=this.value;value1 = key1.replace(/[\u4e00-\u9fa5]/g,' ');if(value1.length>500) this.value=this.value.substr(0,500)"
      onkeyup="key1=this.value;value1 = key1.replace(/[\u4e00-\u9fa5]/g,' ');if(value1.length>500) this.value=this.value.substr(0,500)"
      onblur="key1=this.value;value1 = key1.replace(/[\u4e00-\u9fa5]/g,' ');if(value1.length>500) this.value=this.value.substr(0,500)" 
      onchange="key1=this.value;value1 = key1.replace(/[\u4e00-\u9fa5]/g,' ');if(value1.length>500) this.value=this.value.substr(0,500)"></textarea>

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wdwzgz.html