textCounting 介绍
The jQuery textCounting plugin will count the number of characters or ‘words’
(blocks of characters separated by one or more spaces) in a
The default behavior of the plugin is to display the number of characters left
before reaching the limit (a character countdown). You can use the plugin for
this purpose “as is” (without specifying or changing any settings) if you
follow these conventions in your coding:
- The
must have an “id” attribute with a unique value and a “maxLength” attribute with an integer denoting the character limit. - The display element (
,>,
,etc.) where you want the countdown displayed must have an “id” attribute whose value is the combination of the‘s “id” value and the word “Down”. Here’s an example of a
and a element that fit the
convention:<textarea id="comments" maxLength="1000" rows="4" cols="60"></textarea> <p>Characters left: <span id="commentsDown"></span></p>
Because the element ids and the maxLength value is specific to each
, you can use a single call of the plugin to display a countdown for
all yourelements: <script language="javascript"> $(document).ready(function() $(":input[type=textarea]").textCounting(); }); </script>
If the default plugin behavior is not suitable, the plugin has a number of
settings that can be changed. Here are a few examples:- You can change the countWhat setting to count “words” instead of “characters.”
- The countDirection setting can be set to “up” to count the words/characters in the
, “down” to count the words/characters left before hitting the limit, or “up,down” to count and display both values. - Instead of setting the word/character limit in an attribute of the
, you can pass a comma-delimited list of limits (one per ) into the maxLengthList plugin setting, or you can make use of another jQuery plugin, the Metadata plugin, and set the limit in a block of Metadata within the ‘s “class” attribute. - You can set the plugin to apply a particular CSS class to the element that displays the current count when the limit has been exceeded with the lengthExceededClass setting.
textCounting 官网
http://plugins.jquery.com/project/textCounting
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。