任何人都选择了在contentEditable上更改不透明度.
我试过以下:
document.execCommand('foreColor',false,'rgba(0,0.5)'); // with rgba document.execCommand('foreColor','80000000'); // with alpha hex
没人工作.但我可以轻松改变颜色:
document.execCommand('foreColor','000000');
任何人都可以通过document.execCommand帮助我改变不透明度吗?
更新
进一步搜索发现:
document.execCommand’foreColor’使用给定颜色添加字体标签.但遗憾的是HTML5中不支持颜色属性.
这就是问题吗?它的替代品是什么?
解决方法
您必须使用styleWithCSS命令,该命令指定execCommand方法是否应将CSS或HTML格式生成到文档中.
请参阅此处的规格:https://dvcs.w3.org/hg/editing/raw-file/tip/editing.html#the-stylewithcss-command.
因此,在这种情况下,传递true以使用CSS样式而不是生成字体标记.
片段:
function setColor() { document.execCommand('styleWithCSS',true); document.execCommand('foreColor',"rgba(0,0.5)"); }
<p contentEditable="true" onmouseup="setColor();">this is some text</p>
这将生成应用了CSS的HTML,如下所示:
<p contenteditable="true" onmouseup="setColor();"> this is <span style="color: rgba(0,0.498039);">some</span> text </p>
希望有所帮助.
.
原文地址:https://www.jb51.cc/html/226358.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。