Zi 字媒體
2017-07-25T20:27:27+00:00
textarea auto height
textarea {
resize: none;
}
$(document).ready(function() {
$("textarea.auto-height").css("overflow", "hidden").bind("keydown keyup", function() {
$(this).height('0px').height($(this).prop("scrollHeight") + 'px');
}).keydown();
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>textarea auto height</title>
type="text/css">
textarea {
resize: none;
}
type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
type="text/javascript">
$(document).ready(function() {
$("textarea.auto-height").css("overflow", "hidden").bind("keydown keyup", function() {
$(this).height('0px').height($(this).prop("scrollHeight") + 'px');
}).keydown();
});
</head>
<body>
<textarea class="auto-height"></textarea>
</body>
</html>
[jQuery] textarea自動調整高度 was last modified: 2017-02-06 by Calos
寫了
5860316篇文章,獲得
23313次喜歡