简体   繁体   English

IE中的Execcommand格式块标题

[英]Execcommand formatblock headings in IE

I want to format selected text to a heading, the way I am doing it works fine in Firefox and Google Chrome but it doesn't work in IE9, here is how I do it: 我想将选定的文本格式化为标题,我在Firefox和Google Chrome中的工作方式很好,但它在IE9中不起作用,我的方法如下:

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

Does anyone know how to achieve the same task in Internet Explorer 9? 有谁知道如何在Internet Explorer 9中实现相同的任务?

The problem seems to be one of syntax. 问题似乎是语法之一。 IE expects the tag to be formatted while the other browsers don't. IE期望标记格式化而其他浏览器不格式化。

See here : 看到这里

In Internet Explorer, the name of the element must be placed between tag delimiters (such as <H1> ). 在Internet Explorer中,元素的名称必须放在标记分隔符(例如<H1> )之间。 Firefox, Opera, Google Chrome and Safari support all block elements, Internet Explorer supports only the h1 - h6, address and pre elements Firefox,Opera,Google Chrome和Safari支持所有块元素,Internet Explorer仅支持h1-h6,地址和pre元素

Internet Explorer仅支持标题标记H1 - H6ADDRESSPRE ,它们还必须包含标记分隔符<> ,例如<H1>

works perfect for me in IE9 在IE9中对我来说非常适合

your codes probably wrong, mines more like: 你的代码可能错了,地雷更像是:

        var contentWindow = editor.contentWindow;
        contentWindow.focus();
        contentWindow.document.execCommand('formatBlock', false, '<h1>');
        contentWindow.focus();

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

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