2012-07-14 29 views
-2

哪個好(小巧易用)jquery插件控制textarea中的字符數量我可以用嗎?characteres jquery count

當您輸入一個字符時,如果超過了最大數量,該字符應該被刪除。

我不應該允許輸入一定數量的字符(參數),與Internet Explorer 6.0兼容,並在複製和粘貼文本時工作。

+0

可能重複:http://stackoverflow.com/questions/5371089/jquery -count-characters-in-textarea – 2012-07-14 17:52:36

+0

有沒有理由不能使用默認的'maxlength'? '' – Ohgodwhy 2012-07-14 17:56:57

+0

並且記住任何客戶端字符長度檢查都需要在服務器上重複。切勿僅在客戶端進行檢查。 – Utkanos 2012-07-14 18:00:19

回答

0

那麼,我同意使用maxlength屬性。 但是,如果你也想使用textarea,你需要使用一個插件。
(據我所知最大長度不textarea的工作。)

考慮使用jQuery validatorAnother site here):

$(function() { 

$("#yourform").validate({ 
    rules: { 
     theinputname: "therule" 
    }, 
    messages: { 
     theinputname: "iferror" 
    } 
}); 

}); 
1

你根本就不需要任何javascript。只需輸入一個maxlength =「somenumber」。即使它是一個文本區域。看到我的jsfiddle在這裏http://jsfiddle.net/XKxHq/

+0

對不起,是textarea我的html標記。 – Martin 2012-07-14 18:12:56

+0

它在Internet Explorer 6.0中不起作用。只有在新的瀏覽器中。 http://stackoverflow.com/questions/4372413/textarea-maxlength-supported-or-not-supported – Martin 2012-07-14 22:43:39