html contentEditable document.exec命令更改选定的不透明度
发布时间:2020-12-14 18:27:21 所属栏目:资源 来源:网络整理
导读:任何人都选择了在contentEditable上更改不透明度. 我试过以下: document.execCommand('foreColor',false,'rgba(0,0.5)'); // with rgbadocument.execCommand('foreColor','80000000'); // with alpha hex 没人工作.但我可以轻松改变颜色: document.execCom
任何人都选择了在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> 希望有所帮助. . (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |