天天看點

HTML的TextArea标記跟随文本内容自動設定高度

<script type="text/javascript">

    function get_text_rows(text) {

        return text.split("\n").length;

    }

    $(document).ready(function () {

        document.getElementById('ctl00_jiSubCon_txtJobDescribe').rows = get_text_rows($('#ctl00_jiSubCon_txtJobDescribe').val());

        document.getElementById('ctl00_jiSubCon_txtJobNeed').rows = get_text_rows($('#ctl00_jiSubCon_txtJobNeed').val());

        document.getElementById('ctl00_jiSubCon_txtContactMode').rows = get_text_rows($('#ctl00_jiSubCon_txtContactMode').val());

    });

</script>

<script>

    var textarea = document.getElementById('ctl00_jiSubCon_txtJobDescribe');

    textarea.style.height = textarea.scrollHeight + 'px';

    var textarea2 = document.getElementById('ctl00_jiSubCon_txtJobNeed');

    textarea2.style.height = textarea2.scrollHeight + 'px';

    var textarea3 = document.getElementById('ctl00_jiSubCon_txtContactMode');

    textarea3.style.height = textarea3.scrollHeight + 'px';

</script>  

http://my.oschina.net/ldaga/blog/156399

繼續閱讀