Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;(function(jQuery){
- jQuery.fn.clearTextLimit = function() {
- return this.each(function() {
- this.onkeydown = this.onkeyup = null;
- });
- };
- jQuery.fn.textLimit = function( limit , callback ) {
- if ( typeof callback !== 'function' ) var callback = function() {};
- return this.each(function() {
- this.limit = limit;
- this.callback = callback;
- this.onkeydown = this.onkeyup = function() {
- this.value = this.value.substr(0,this.limit);
- this.reached = this.limit - this.value.length;
- this.reached = ( this.reached == 0 ) ? true : false;
- return this.callback( this.value.length, this.limit, this.reached );
- }
- });
- };
- })(jQuery);
- jQuery('textarea').textLimit(100,function( length, limit ){
- jQuery(this).next().text( limit - length );
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement