zoukankan      html  css  js  c++  java
  • 文本框高度自适应

    <!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>文本框高度自适应</title>
        <style type="text/css">
            #shadow, #text { font: 12px/16px Arial;  200px; overflow: hidden; height: 16px; }
            #shadow { position: absolute; border- 0px; padding: 0px; visibility: hidden; }
            #text { resize: none; }
        </style>
        <script type="text/javascript">
           
            window.onload = function () {
                var text = document.getElementById("text"); //用户看到的文本框
                var shadow = document.getElementById("shadow"); //隐藏的文本框
    
                text.oninput = //非IE的
                text.onpropertychange = //IE的
                onchange;
                
                function onchange() {
                    shadow.value = text.value;
                    setHeight();
                    setTimeout(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>
  • 相关阅读:
    软件工程第二次作业
    软件工程第1次作业
    软件工程第0次作业
    第4次作业-案例分析
    第3次作业-四则运算
    第2次作业-效能分析
    第1次作业-词频统计
    第0次作业
    关于 石墨文档客户端 的案例分析
    结对编程
  • 原文地址:https://www.cnblogs.com/huanlei/p/2473132.html
Copyright © 2011-2022 走看看