2011-04-27 340 views
0

我想限制使用jquery的html jQuery富文本編輯器中的字符數。最大限制爲1000個字符。如果刪除某些字符,我只能將數據添加到該字符中從上下文菜單複製粘貼即使在達到極限後也不應起作用。限制富文本編輯器中的字符數

回答

0

使用下面的JavaScript代碼: -

function checkBox(){if(document.getElementById("**ELEMENT NAME**").value.length>1000){document.getElementById("**ELEMENT NAME**").value = document.getElementById("**ELEMENT NAME**").value.substring(0, 1000);}} 
window.setInterval("checkBox();", 1000); 

希望這有助於

+0

這作品是什麼簡單的文本編輯器,而不是HTML jQuery編輯器 – user726490 2011-04-27 12:53:42

+0

如果您正在使用JQuery,那麼它仍然可以正常工作!無論如何,總是在那裏幫助! :d – 2011-04-27 13:19:07

0
//This is not jQuery, but it will do the trick 

<html> 
    <head> 
    <script language="JavaScript"> 
    <!-- 
     function limitText() { 
     var txtArea = document.myForm.myTextArea; 
     if (txtArea.value.length > 1000) { 
      txtArea.value = txtArea.value.substring(0, 999); 
     } 
    } 
    --> 
    </script> 
</head> 
    <body> 
    <form name="myForm"> 
     <textarea name="myTextArea" rows=2 cols=50 onChange='limitText()'> 
     Here is some text in my text area. 
     </textarea> 
    </form> 
    </body>