相关疑难解决方法(0)

textarea字符限制

我希望能够限制textarea中的字符数.我使用的方法在谷歌浏览器中效果很好,但在Firefox中很慢,并且在IE中不起作用.

使用Javascript:

function len(){
  t_v=textarea.value;
  if(t_v.length>180){
    long_post_container.innerHTML=long_post;
    post_button.className=post_button.className.replace('post_it_regular','post_it_disabled');
    post_button.disabled=true;
  }
  else{
    long_post_container.innerHTML="";
    post_button.className=post_button.className.replace('post_it_disabled','post_it_regular');
    post_button.disabled=false;
  }
  if(t_v.length>186){
        t_v=t_v.substring(0,186);
    }
}
Run Code Online (Sandbox Code Playgroud)

HTML:

<textarea id="user_post_textarea" name="user_post_textarea" cols="28" rows="1"  onkeypress="len();" onkeyup="len();"></textarea>
Run Code Online (Sandbox Code Playgroud)

body元素底部的Javascript:

textarea=document.getElementById('user_post_textarea');
Run Code Online (Sandbox Code Playgroud)

html javascript textarea cross-browser

27
推荐指数
2
解决办法
10万
查看次数

文本区域的最大长度在IE中不起作用

我试图限制在textarea中输入的字符数,如下所示:

<div>
 @Html.TextAreaFor(x => x.StudentName, new { @maxlength = "1000" })
</div>
Run Code Online (Sandbox Code Playgroud)

这在Firefox和Chrome中运行良好,但maxlength属性在IE中不起作用.我怎么做??

html asp.net-mvc-3

25
推荐指数
2
解决办法
6万
查看次数

限制textarea中可以粘贴的字符数

是否可以检测到粘贴到HTML文本区域中的字符数,如果超出限制则取消粘贴?

编辑:我想要做的是阻止用户粘贴大量的字符(约300万),因为它崩溃了一些浏览器.所以我想在浏览器锁定之前取消粘贴.我正在制作一个文档编辑器,用户可能会尝试这样做.但他们可以根据自己的意愿打字.

html jquery textarea copy-paste

11
推荐指数
2
解决办法
2万
查看次数