This article describes how to implement the automatic height of the multi-line text box [textarea] using the jquery plug-in. if you need it, refer to the following implementation functions:
1. when textarea is changed, the height of a row is automatically increased.
2/when textarea deletes a row, the high dependency of the row is automatically reduced: jquery. xxx. js requires similar functions, but it is inconvenient to import other files to the plug-in.
Textarea jquery plugin
The code is as follows:
Content
The code is as follows:
JQuery. extend ({
TextareaAutosize_dc: function (){
$ ("Textarea"). on ("keyup", function (e ){
Var currentEnterCount = $ (this). val (). split ("\ n"). length;
Var lineHeight = number(((this).css ("line-height"). replace ("px ",""));
Var enterCount = $ (this). attr ("enterCount ");
If (currentEnterCount <enterCount & enterCount! = Undefined ){
// Remove the fixed row height from each row
$ (This). height ($ (this). height ()-lineHeight );
} Else if (currentEnterCount> enterCount ){
// Add fixed row height to each row
$ (This). height ($ (this). height () + lineHeight );
$ (This). attr ("enterCount", currentEnterCount );
}
// Record the current row height
$ (This). attr ("enterCount", currentEnterCount );
});
}
});
// Automatic call height
$. TextareaAutosize_dc ();
The above is all the content of this article. I hope you will like it.