تصف هذه المقالة طريقة JS لتنفيذ مربعات نص نموذج الارتفاع التكيفي. شاركه للرجوع إليه. طريقة التنفيذ المحددة هي كما يلي:
انسخ الرمز على النحو التالي: <! doctype html public "-// w3c // dtd xhtml 1.0 transitional // en" "http://www.w3
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<TITLE> JS تنفذ مربع نص نموذج الارتفاع التكيفي </title>
<type type = "text/css">
#shadow ، #text {font: 12px/16px arial ؛ العرض: 200 بكسل ؛ الفائض: مخفي. الارتفاع: 16 بكسل ؛ }
#shadow {position: absolute ؛ عرض الحدود: 0px ؛ الحشو: 0px ؛ الرؤية: مخفية ؛ }
#Text {تغيير الحجم: لا شيء ؛ }
</style>
<script type = "text/javaScript">
window.onload = function () {
var text = document.getElementById ("text") ؛ // مربع النص الذي يراه المستخدم
var Shadow = document.getElementById ("Shadow") ؛ // مربع النص المخفي
text.oninput = // noni
text.onpropertyChange = // ie'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"> </sextarea>
<textarea id = "shadow"> </textarea>
</body>
</html>
آمل أن تكون هذه المقالة مفيدة لبرمجة JavaScript للجميع.