jQuery Textarea 字符统计插件

This plugin allows you to set and limit user input by max characters within html textarea (it is only limited by characters other than words). It binds keyup, paste and drag events. The extra div is displayed under the textarea, which shows the current number of input characters and words. You can set your own styles and customise the text counter information. Version 2 provides the callback function.
Notice: For windows OS, new line character occupies two characters (\r\n) instead of one (\n)


演示地址:
http://roy-jin.appspot.com/jsp/textareaCounter.jsp

使用步骤:

 

  • Step One: Version 2 Config Options  
    [For Version One config doc, please download version one package right side.]
     
    OptionsDescription
    maxCharacterSizeDefine the maximum number of characters. Default is -1. Limit characters does work only when maxCharacterSize > 0
    originalStyleSet original class style
    warningStyleSet warning class style
    warningNumberIf number of characters of user input is over the warning number, the information style will be changed to warning style.
    displayFormatDefine your display information format. There are four keywords: #input, #max, #left, #words.
    • #input: represents your current number of input characters
    • #max: represents your predefined max character size
    • #left: represents how many characters you left
    • #words: represents your current number of input words

    For example: 'displayFormat' : '#input characters and #words words'
    The result will be: 123 characters and 20 words.
    #input and #words will be substituted by current characters and words
    Remeber:#max and #left does work only when maxCharacterSize > 0
  • Step Two: Add Callback function 

    In the 3rd example, you saw that not only counter information was shown but also extra information was displayed in the div above the textarea This is done by the callback function.

    1. $('#testTextarea3').textareaCount(options3, function(data){   
    2.     var result = 'Characters Input: ' + data.input + '<br />';   
    3.      result += 'Words Input: ' + data.words + '<br />';   
    4.      result += 'Left Characters: ' + data.left + '<br />';   
    5.      result += 'Characters Limitation: ' + data.max + '<br />';   
    6.     $('#textareaCallBack').html(result);   
    7. });   
    					$('#testTextarea3').textareaCount(options3, function(data){
    						var result = 'Characters Input: ' + data.input + '<br />';
    						 result += 'Words Input: ' + data.words + '<br />';
    						 result += 'Left Characters: ' + data.left + '<br />';
    						 result += 'Characters Limitation: ' + data.max + '<br />';
    						$('#textareaCallBack').html(result);
    					});
    				

    You can pass user defined function as an argument after options.
    Function data is an object, which contains four values:

    • data.input: current number of input characters
    • data.max: max character size
    • data.left: how many left characters
    • data.words: current number of input words

     

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值