Function implementation:
1/Automatically increase the height of a line when the textarea wraps
2/When textarea deletes a line, the height of the line is automatically reduced. Dependency: jquery.xxx.js I need to use similar functions at work, but I find it inconvenient to use plug-ins to import other files, so I wrote one
textarea jquery plug-in
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) {
//Subtract the fixed row height from each row
$(this).height($(this).height() - lineHeight);
} else if (currentEnterCount > enterCount) {
//Add a fixed row height to each row
$(this).height($(this).height() lineHeight);
$(this).attr("enterCount", currentEnterCount);
}
//Record the current row height
$(this).attr("enterCount", currentEnterCount);
});
}
});
//Call automatic height
$.textareaAutosize_dc();
The above is the entire content of this article, I hope you all like it.