HTML的TextArea標記跟隨文本內容自動設置高度

<script type="text/javascript">javascript

    function get_text_rows(text) {java

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

    }.net

    $(document).ready(function () {blog

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

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

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

    });io

</script>function

<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

相關文章
相關標籤/搜索