zoukankan      html  css  js  c++  java
  • Textarea自适应高度 JS实现,兼容IE67891011

    <!DOCTYPE html>
    <html>
    <head>
    <title>autoresizing textarea</title>
    <style type="text/css">
    textarea {
        border: 0 none white;
        overflow: hidden;
        padding: 0;
        outline: none;
        background-color: #FFFFFF;
        resize: none;
    }
    </style>
    <script type="text/javascript">
    var observe;
    if (window.attachEvent) {
        observe = function (element, event, handler) {
            element.attachEvent('on'+event, handler);
        };
    }
    else {
        observe = function (element, event, handler) {
            element.addEventListener(event, handler, false);
        };
    }
    function init () {
        var text = document.getElementById('text');
        function resize () {
            text.style.height = 'auto';
            text.style.height = text.scrollHeight+'px';
        }
        /* 0-timeout to get the already changed text */
        function delayedResize () {
            window.setTimeout(resize, 0);
        }
        observe(text, 'change',  resize);
        observe(text, 'cut',     delayedResize);
        observe(text, 'paste',   delayedResize);
        observe(text, 'drop',    delayedResize);
        observe(text, 'keydown', delayedResize);
        text.focus();
        text.select();
        resize();
    }
    </script>
    </head>
    <body onload="init();">
    <textarea cols="40" rows="1" style="height:25px;" id="text"></textarea>
    </body>
    </html>
  • 相关阅读:
    HDU 4339 Query
    Another app is currently holding the yum lock解决方法
    m0n0wall安装教程
    网盘
    kali 网络配置
    monowall
    Windows server 2012安装vmtools遇到的问题
    利用WPF建立自适应窗口大小布局的WinForm窗口
    wpf倒影效果
    SQL 进制间如何转换
  • 原文地址:https://www.cnblogs.com/jlove/p/4667359.html
Copyright © 2011-2022 走看看