JavaScript文件。execCommand删除formatBlock格式化?

时间:2022-11-25 20:15:16

If I format a piece of text on a page like this:

如果我在这样的页面上格式化一段文字:

document.execCommand('formatBlock', false, 'h1');

What do I do to remove this formatting?

我要如何删除这种格式?

2 个解决方案

#1


13  

I suppose document.execCommand('removeFormat',false,false) would do it?

我想document。execcommand ('removeFormat',false,false)行吗?

Issuing document.execCommand('formatBlock', false, 'div') on the <h1>-block will remove the <h1>-tag and replace it with a <div>-tag 1. Would that be viable?

发布文档。在

块上的execCommand('formatBlock', false, 'div')将删除

-tag,并将其替换为
-tag 1。这是可行的吗?

1 If you're not using IE that is

如果你不使用IE,那是

#2


0  

you may have to find the parent tag, then use innerHTML to get the text and replace the original data between the parent tag and end-tag with the innerHTML. This would however remove all formatting.

您可能需要找到父标记,然后使用innerHTML获取文本,并用innerHTML替换父标记和结束标记之间的原始数据。但是,这将删除所有格式。

#1


13  

I suppose document.execCommand('removeFormat',false,false) would do it?

我想document。execcommand ('removeFormat',false,false)行吗?

Issuing document.execCommand('formatBlock', false, 'div') on the <h1>-block will remove the <h1>-tag and replace it with a <div>-tag 1. Would that be viable?

发布文档。在

块上的execCommand('formatBlock', false, 'div')将删除

-tag,并将其替换为
-tag 1。这是可行的吗?

1 If you're not using IE that is

如果你不使用IE,那是

#2


0  

you may have to find the parent tag, then use innerHTML to get the text and replace the original data between the parent tag and end-tag with the innerHTML. This would however remove all formatting.

您可能需要找到父标记,然后使用innerHTML获取文本,并用innerHTML替换父标记和结束标记之间的原始数据。但是,这将删除所有格式。