内容简介:之前一直没有留意到有为了某个使元素可编辑,你所要做的就是在html标签上设置
前言
之前一直没有留意到有 contenteditable 这个属性,今天突然看到特意记录一下它的 用法 和 实际用途 ;
用法
为了某个使元素可编辑,你所要做的就是在html标签上设置 "contenteditable" 属性,它几乎支持所有的HTML元素。
contenteditable 有以下几种属性:
"true" "false" "inherit"
<div contenteditable="true"> This text can be edited by the user. </div>
通过一下代码,可以观察到如果子元素没有设置 contenteditable 属性,其默认值继承自父元素(既默认为 "inherit" 属性)
<div contenteditable="true"> <p>Edit this content to add your own quote</p> <p>Edit this content to add your own quote - 2</p> </div>
可以使用css中 caret-color 属性设置文本插入光标的颜色。
实际用途
2.避免处理input、textarea的内含样式
CSS user-modify
使用css中的 user-modify 属性,也可以让普通元素可以读写。
/* Keyword values */ user-modify: read-only; (默认值) user-modify: read-write; user-modify: write-only; user-modify: read-write-plaintext-only; (只允许输入纯文本,但兼容性很差) /* Global values */ user-modify: inherit; user-modify: initial; user-modify: unset;
举个例子:
<div class="readwrite">The user is able to change this text.</div>
.readwrite {
-moz-user-modify: read-write;
-webkit-user-modify: read-write;
}
相对于 contenteditable 而言, user-modify 的兼容性就没那么理想了。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- CSS 属性篇(七):Display属性
- JavaScript对象之数据属性与访问器属性
- Logback file属性 与 fileNamePattern属性的关系
- 浅谈Spring Boot 属性配置和自定义属性配置
- python – Django属性错误. ‘module’对象没有属性’rindex’
- 深度解析属性动画的思想 - 带你手动实现属性动画框架
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Data Structures and Algorithm Analysis in Java
Mark A. Weiss / Pearson / 2011-11-18 / GBP 129.99
Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course wa......一起来看看 《Data Structures and Algorithm Analysis in Java》 这本书的介绍吧!