admin管理员组文章数量:1201362
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.
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).
Is this possible?
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.
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).
Is this possible?
Share Improve this question asked Oct 1, 2010 at 20:48 Nico BurnsNico Burns 17.1k10 gold badges42 silver badges55 bronze badges2 Answers
Reset to default 17I'm having success with the following:
document.execCommand("removeFormat", false, "foreColor");
Seems (so far) that removeFormat
can be understood to remove only formatting created by a particular command.
Here's a partial answer, but I'm still looking for a solution for Chrome:
In IE9, you can use the following:
document.execCommand("foreColor",false,"")
In Firefox, you can use this:
document.execCommand("foreColor",false,"inherit")
But in Chrome, passing null/empty string does nothing, while passing 'inherit' results in setting the text color to "rgba(0, 0, 0, 0)" -- transparent black. Clearly this is a bug. I would love to see a more reliable cross-browser way to do this.
本文标签:
版权声明:本文标题:javascript - Contenteditable reset text color after foreColor has been used without resetting other styles - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738566523a2100256.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论