textarea:contenteditable模拟文本域-纯文本-chrome浏览器,其余不兼容

1.  与contenteditable属性无关的CSS控制法  
只有webkit内核浏览器才支持read-write-plaintext-only

一个div元素,要让其可编辑,也就是可读写,contenteditable属性是最常用方法,做前端的基本上都知道。但是,知道CSS中有属性可以让普通元素可读写的的同学怕是就少多了。

主角亮相:user-modify.

支持属性值如下:

user-modify: read-only;
user-modify: read-write;
user-modify: write-only;
user-modify: read-write-plaintext-only;
其中, write-only 不用在意,当下这个年代,基本上没有浏览器支持,以后估计也不会有。 read-only 表示只读,就是普通元素的默认状态啦。
然后,read-writeread-write-plaintext-only会让元素表现得像个文本域一样,可以focus以及输入内容
两者的区别就在于,一个可以输入富文本,而下面一个只能输入纯文本
read-write-plaintext-only  {
  1. -webkit-user-modifyread-write-plaintext-only;}
test {
    height: 100px;
    padding: 5px;
    border: 1px solid #a0b3d6;
    overflow: auto;}
<p class="test  read-write-plaintext-only"></p>

2. 使用标准contenteditable属性值的HTML控制法

目前仅仅是Chrome浏览器支持比较好的。
contenteditable=""
contenteditable="events"
contenteditable="caret"
contenteditable="plaintext-only"  
contenteditable="true"
contenteditable="false"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值