div标签模拟textarea

来源:互联网 发布:淘宝夜店装 编辑:程序博客网 时间:2024/06/08 03:22

只需要将div设为contenteditable即可

  • 以下是例子
<!DOCTYPE html><!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]--><!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]--><!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]--><!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->    <head>        <meta charset="utf-8">        <meta http-equiv="X-UA-Compatible" content="IE=edge">        <title>div模拟textarea</title>        <meta name="description" content="">        <meta name="viewport" content="width=device-width, initial-scale=1">        <style>            .virtual-textarea{                min-height: 100px;                max-height: 300px;                width: 300px;                overflow-x: hidden;                overflow-y: auto;                border: 1px solid #f60;            }        </style>    </head>    <body>        <!--[if lt IE 7]>            <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="#">upgrade your browser</a> to improve your experience.</p>        <![endif]-->        <div class="virtual-textarea" contenteditable></div>    </body></html>

  • 效果展示
    这里写图片描述

以上

原创粉丝点击