内容简介:之前一直没有留意到有为了某个使元素可编辑,你所要做的就是在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’
- 深度解析属性动画的思想 - 带你手动实现属性动画框架
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
C++ Primer 中文版(第 5 版)
[美] Stanley B. Lippman、[美] Josée Lajoie、[美] Barbara E. Moo / 王刚、杨巨峰 / 电子工业出版社 / 2013-9-1 / CNY 128.00
这本久负盛名的 C++经典教程,时隔八年之久,终迎来史无前例的重大升级。除令全球无数程序员从中受益,甚至为之迷醉的——C++ 大师 Stanley B. Lippman 的丰富实践经验,C++标准委员会原负责人 Josée Lajoie 对C++标准的深入理解,以及C++ 先驱 Barbara E. Moo 在 C++教学方面的真知灼见外,更是基于全新的 C++11标准进行了全面而彻底的内容更新。......一起来看看 《C++ Primer 中文版(第 5 版)》 这本书的介绍吧!