用一个div模拟textarea的实现

HTML5属性Contenteditable实现div可编辑
Css

<style type="text/css">
    .demo{
            width: 400px;
            min-height: 100px;
            max-height: 300px;
            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;
    }
</style>

Html

<div contenteditable="true" class="demo">
    啦啦啦
</div>

演示地址:预览

发表新评论