【发布时间】:2018-10-13 14:33:55
【问题描述】:
我需要一个帮助。我需要根据里面写的内容来修复文本区域的高度。我在下面解释我的代码。
<html>
<head>
<link rel="stylesheet" href="lib/style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="lib/script.js"></script>
</head>
<body>
<h1>Hello</h1>
<textarea id="textarea-container">
Line 1
Line 2
Line 3
Line 4
ccccccccccccccccccccc
</textarea>
<script>
var $textArea = $("#textarea-container");
// Re-size to fit initial content.
resizeTextArea($textArea);
// Remove this binding if you don't want to re-size on typing.
$textArea.off("keyup.textarea").on("keyup.textarea", function() {
resizeTextArea($(this));
});
function resizeTextArea($element) {
$element.height($element[0].scrollHeight);
}
</script>
</body>
</html>
这里有一些文本存在于文本区域及其滚动中。我需要在这里文本区域的高度将根据其中存在的内容扩展,并且不会滚动。
【问题讨论】:
-
impressivewebs.com/demo-files/textarea-auto-resize 如果上面的链接正是您想要的。这是完整代码的链接。 impressivewebs.com/textarea-auto-resize谢谢