Javascript IE中的Execcommand格式块标题
我想将所选文本格式化为标题,我的做法在Firefox和Google Chrome中运行良好,但在IE9中不起作用,以下是我的做法:Javascript IE中的Execcommand格式块标题,javascript,html,internet-explorer,firefox,google-chrome,Javascript,Html,Internet Explorer,Firefox,Google Chrome,我想将所选文本格式化为标题,我的做法在Firefox和Google Chrome中运行良好,但在IE9中不起作用,以下是我的做法: document.execCommand('formatBlock',false,'h1'); 有人知道如何在Internet Explorer 9中完成相同的任务吗?在IE9中非常适合我 你的代码可能是错的,我更喜欢: var contentWindow = editor.contentWindow; contentWindow.
document.execCommand('formatBlock',false,'h1');
有人知道如何在Internet Explorer 9中完成相同的任务吗?在IE9中非常适合我 你的代码可能是错的,我更喜欢:
var contentWindow = editor.contentWindow;
contentWindow.focus();
contentWindow.document.execCommand('formatBlock', false, '<h1>');
contentWindow.focus();
var contentWindow=editor.contentWindow;
contentWindow.focus();
contentWindow.document.execCommand('formatBlock',false',);
contentWindow.focus();
问题似乎在于语法。IE希望标记被格式化,而其他浏览器不这样做
见:
在Internet Explorer中,元素的名称必须放在
标记分隔符(例如
)。Firefox、Opera、Google Chrome和
Safari支持所有块元素,Internet Explorer仅支持
h1-h6,地址和前置元素
Internet Explorer仅支持标题标记
H1
-H6
、地址
和PRE
,还必须包括标记分隔符
,例如在
中