我使用粗体(‘execCommand’)将以下文本设置为粗体,但当我再次尝试禁用粗体,然后添加其他标签(如'h‘或其他内容)时,它会添加额外的标签链接:
<h1><span style="font-weight: normal;">111</span></h1>我想知道如何避免这种情况?
发布于 2019-12-27 09:44:43
javascript代码就像这样:
Editor.setHeading = function(heading) {
if(heading == 0){
document.execCommand('formatBlock', false, '<div>')
} else {
document.execCommand('formatBlock', false, '<h'+heading+'>');
}
}
Editor.setBold = function() {
document.execCommand('bold', false, null);
}html是:
<body>
<div id="editor" contenteditable="true"></div>
<script type="text/javascript" src="editor.js"></script>
</body>https://stackoverflow.com/questions/59477616
复制相似问题