document.execCommand("delete");
document.execCommand("insertText", false, insertString);
以上两个命令在 Chrome/Firefox 中工作得很好,但我无法在 IE11 中使用它。
document.execCommand("delete")
仅当我们选择一段文本时才能在 IE 中使用。我如何让它像在 Chrome 中一样工作(即像使用退格键一样)。
还有我如何在 IE 中使用 document.execCommand("insertText", false, insertString)
。
最佳答案
对于 IE 中的 insertText,有解决方法:
let isIE = function() {
return document.all || (!!window.MSInputMethodContext && !!document.documentMode);
}
let text = "Hello"
if(isIE()) document.execCommand("paste", false, text);
关于javascript - 无法使用 execCommand 在 IE11 div contentEditable 中删除或插入文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53247049/