Home>Article>Web Front-end> Set multi-line text box [textarea] to automatically generate height

Set multi-line text box [textarea] to automatically generate height

php中世界最好的语言
php中世界最好的语言 Original
2018-04-26 13:42:09 2579browse

This time I will bring you settingsMulti-line text box[textarea] automatically generates height, set multi-line text box[textarea] to automatically generate heightWhat are the precautions, The following is a practical case, let’s take a look.

Implementation functions:

1/Automatically increase the height of a row when the textarea wraps a new line
2/Automatically reduce the height of a row when the textarea deletes a row Dependency: jquery.xxx.js Needed for work I use similar functions but find it inconvenient to import other files when using a plug-in, so I wrote a

textarea jquery plug-in

jQuery.extend({ textareaAutosize_dc: function() { $("textarea").on("keyup", function(e) { var current EnterCount = $(this).val().split("\n").length; var lineHeight = Number($(this).css(" line-height ").replace("px", "")); var enterCount = $(this).attr("enterCount"); if (currentEnterCount < enterCount && enterCount != undefined) { //每行减掉固定行高 $(this).height($(this).height() - lineHeight); } else if (currentEnterCount > enterCount) { //每行加入固定行高 $(this).height($(this).height() + lineHeight); $(this).attr("enterCount", currentEnterCount); } //记录当前行高 $(this).attr("enterCount", currentEnterCount); }); } }); //调用自动高度 $.textareaAutosize_dc();

I believe you have mastered the method after reading the case in this article, please come for more exciting information Pay attention to other related articles on php Chinese website!

Recommended reading:

Jquery Mobile Custom Button Icon Steps Detailed Explanation

Jquery Mobile Custom Button Icon Steps Detailed Explanation

The above is the detailed content of Set multi-line text box [textarea] to automatically generate height. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn