บทความนี้อธิบายวิธีการของ JS ในการใช้กล่องข้อความแบบฟอร์มความสูงแบบปรับตัว แบ่งปันสำหรับการอ้างอิงของคุณ วิธีการใช้งานเฉพาะมีดังนี้:
คัดลอกรหัสดังนี้: <! Doctype html public "-// w3c // dtd xhtml 1.0 transitional // en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<title> js ใช้กล่องข้อความแบบฟอร์มความสูงแบบปรับตัว </title>
<style type = "text/css">
#shadow, #text {ตัวอักษร: 12px/16px Arial; ความกว้าง: 200px; ล้น: ซ่อน; ความสูง: 16px; -
#shadow {ตำแหน่ง: สัมบูรณ์; ความกว้างของชายแดน: 0px; Padding: 0px; ทัศนวิสัย: ซ่อน; -
#text {Resize: None; -
</style>
<script type = "text/javascript">
window.onload = function () {
var text = document.getElementById ("ข้อความ"); // กล่องข้อความที่ผู้ใช้เห็น
var shadow = document.getElementById ("Shadow"); // กล่องข้อความที่ซ่อน
text.oninput = // nonie
text.onProperTyChange = // ie's's
onchange;
ฟังก์ชั่น onchange () {
Shadow.value = text.value;
Setheight ();
Settimeout (Setheight, 0); // สำหรับความล่าช้าของ IE 6/7/8 มิฉะนั้นจะมีรายการอักขระและออก
ฟังก์ชั่น setheight () {text.style.height = shadow.scrollheight + "px"; -
-
-
</script>
</head>
<body>
<textarea id = "text"> </textarea>
<textarea id = "shadow"> </textarea>
</body>
</html>
ฉันหวังว่าบทความนี้จะเป็นประโยชน์กับการเขียนโปรแกรม JavaScript ของทุกคน