admin管理员组文章数量:1424993
I created a rich content editor based on execCommand
and queryCommandState
whose are now obsolete. I'm looking for a substitute to these mands, especially for
document.queryCommandState('bold')
I think the following is a good start:
window.getSelection().getRangeAt(0);
I get the current selection, but I can't figure out if the selection is in bold <b>
or not.
I created a rich content editor based on execCommand
and queryCommandState
whose are now obsolete. I'm looking for a substitute to these mands, especially for
document.queryCommandState('bold')
I think the following is a good start:
window.getSelection().getRangeAt(0);
I get the current selection, but I can't figure out if the selection is in bold <b>
or not.
2 Answers
Reset to default 4It can be done with window.getSelection()
JSFiddle: https://jsfiddle/Imabot/s54zoxk2/
Explanations: https://lucidar.me/en/rich-content-editor/lightweight-rich-content-editor-part-2-check-if-bold/
Hope this will help others...
You could get all puted styles of the node and then check the value of your propertie.
function getComputedStyles(currentNode) {
if(currentNode.id != maxTreeNodeId) {
try {
var styles = window.getComputedStyle(currentNode);
console.log(styles.fontWeight); // Print font weight, 700 = bold
} catch(err) {
this.getComputedStyles(currentNode.parentNode);
}
}
}
本文标签: javascriptAlternativesubstitute for queryCommandState(39bold39)Stack Overflow
版权声明:本文标题:javascript - Alternativesubstitute for queryCommandState('bold') - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745422869a2657980.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论