简体   繁体   English

document.execCommand('bold')在React JS中不起作用

[英]document.execCommand('bold') not working in react js

REACT JS : im trying to make simple editor for my project , which can make text bold , italic and underline REACT JS:我正在尝试为我的项目创建简单的编辑器,该编辑器可以使文本加粗,斜体和下划线

im using contentEditable 即时通讯使用contentEditable

<div className="inputBox" contentEditable>some text here to play with</div> 

and im using a button just above it to make text bold 我使用它上方的按钮使文本变为粗体

<div className="button' onClick={this.buttonCLick.bind(this)}>BOLD</div>

which calls this onclick 这称为onclick

buttonCLick(){
        let isWorking = document.execCommand('bold',false,'');
        console.log('isWorking:', isWorking);
    }

but the " isWorking " return false every time and nothing happns to selected text . 但是“ isWorking ”每次都返回false ,所选文本不会发生任何事情。

What browser shows this behavior? 哪个浏览器显示此行为? Have you tried that on different browser? 您是否在其他浏览器上尝试过?

Eg on Firefox you must make sure that default font-weight is 400 ( https://bugzilla.mozilla.org/show_bug.cgi?id=948411 ). 例如,在Firefox上,您必须确保默认字体粗细为400( https://bugzilla.mozilla.org/show_bug.cgi?id=948411 )。 Here I have have reported documentation bug for Firefox https://bugzilla.mozilla.org/show_bug.cgi?id=1515267 在这里,我已经报告了Firefox的文档错误https://bugzilla.mozilla.org/show_bug.cgi?id=1515267

Another exotic case seems to be this, but I have not reproduced that: Why doesn't the document.execCommand work when I click on a div? 另一个奇怪的情况似乎是这种情况,但我没有重现这一点: 当我单击div时为什么document.execCommand不起作用? but

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM