使用foreColor后无需重置其他样式即可获得重置文本颜色 [英] Contenteditable reset text color after foreColor has been used without resetting other styles

查看:104
本文介绍了使用foreColor后无需重置其他样式即可获得重置文本颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更改contenteditable div中文本的文本颜色很简单 - 简单地称为 document.execCommand(foreColor,false,#FFF)来更改文本颜色白色。

Changing the text color of text in a contenteditable div is easy - simply called document.execCommand("foreColor",false,"#FFF") to change text color to white.

但是,我找不到将此颜色重置为其默认值(或父元素的值)的方法。 document.execCommand(removeFormat,false,null)完美无缺,除了它还会删除任何粗体或斜体样式,这不是我想要的。简单地将颜色设置为黑色,除非您在选择中有一个链接(应该保持相同的颜色)。

However, I cannot find a way to reset this color back to its default value (or to the value of the parent element). document.execCommand("removeFormat",false,null) works perfectly, except that it will also remove any bold or italic styles, which is not what I want. Simply setting the color to black works, apart from if you have a link in the selection (which should stay the same color).

这可能吗?

推荐答案

我在以下方面取得了成功:

I'm having success with the following:

document.execCommand("removeFormat", false, "foreColor");

似乎(到目前为止) removeFormat 可以应理解为仅删除特定命令创建的格式。

Seems (so far) that removeFormat can be understood to remove only formatting created by a particular command.

这篇关于使用foreColor后无需重置其他样式即可获得重置文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆