六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 18|回复: 0

jQuery Textarea 字符统计插件

[复制链接]

升级  10.8%

386

主题

386

主题

386

主题

探花

Rank: 6Rank: 6

积分
1216
 楼主| 发表于 2013-2-7 08:17:55 | 显示全部楼层 |阅读模式
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

使用步骤:

 
<ul>Step One: Version 2 Config Options  
[For Version One config doc, please download version one package right side.]
  OptionsDescriptionmaxCharacterSizeDefine the maximum number of characters. Default is -1. Limit characters does work only when maxCharacterSize > 0originalStyleSet original class stylewarningStyleSet warning class stylewarningNumberIf 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.
<div class="dp-highlighter"><div class="bar"><div class="tools">view plaincopy to clipboardprint?
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表