<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>textarea auto height</title>
    <style type="text/css">
    textarea {
        resize: none;
    }
    </style>
    <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function() {
        $("textarea.auto-height").css("overflow", "hidden").bind("keydown keyup", function() {
            $(this).height('0px').height($(this).prop("scrollHeight") + 'px');
        }).keydown();
    });
    </script>
</head>
<body>
    <textarea class="auto-height"></textarea>
</body>
</html>

留言