この記事では、Adaptive Height Formテキストボックスを実装するJSの方法について説明します。参照のためにそれを共有してください。特定の実装方法は次のとおりです。
次のようにコードをコピーします。
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<title> JSは、適応高さの形式テキストボックス</title>を実装しています
<style type = "text/css">
#shadow、#text {font:12px/16px arial;幅:200px;オーバーフロー:隠し;高さ:16px; }
#shadow {position:absolute;境界線:0px;パディング:0px;可視性:隠された; }
#text {resize:none; }
</style>
<script type = "text/javascript">
window.onload = function(){
var text = document.getElementById( "TEXT"); //ユーザーが見たテキストボックス
var Shadow = document.getElementById( "Shadow"); //非表示のテキストボックス
text.oninput = // nonie
text.onpropertychange = // ie's
onchange;
function onchange(){
shadow.value = text.value;
setheight();
setimeout(setheight、0); // IE 6/7/8の遅延の場合、それ以外の場合は文字エントリと出口があります
function setheight(){text.style.height = shadow.scrollheight + "px"; }
}
};
</script>
</head>
<body>
<textarea id = "text"> </textarea>
<textarea id = "Shadow"> </textarea>
</body>
</html>
この記事がみんなのJavaScriptプログラミングに役立つことを願っています。