三、用一個div模擬textarea的實現

一、內容可編輯 contenteditable

    對就是contenteditable,給div添加contenteditable=true便可;                                                                                                                                                                                                                                          web

二、demo

CSS代碼:
.test_box {
    width: 400px; 
    min-height: 120px; 
    max-height: 300px;
    _height: 120px; 
    margin-left: auto; 
    margin-right: auto; 
    padding: 3px; 
    outline: 0; 
    border: 1px solid #a0b3d6; 
    font-size: 12px; 
    word-wrap: break-word;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-user-modify: read-write-plaintext-only;
}
HTML代碼:
<div class="test_box" contenteditable="true"><br /></div>
JS代碼:
if (typeof document.webkitHidden == "undefined") {
    // 非chrome瀏覽器阻止粘貼
    box.onpaste = function() {
        return false;
    }
}
相關文章
相關標籤/搜索