0
<html>
    <head>
        <script>
            function insertHTMLCode() {
                var htmlText = '<b>HI</b>';
                try {
                    document.execCommand('insertHTML', false, htmlText);
                } catch(e) {
                    console.log(e);
                }
            }
        </script>
    </head>
    <body>
        <div>
            <ys_content contenteditable="true"><!-- ~Client References -->
                <font size="2" face="Arial, Helvetica, sans-serif" color="#000000"><strong>More information coming soon...</strong> </font> 
            <!-- ~/Client References -->
            </ys_content>
        </div>
        <input type="button" onclick="insertHTMLCode();" value="Click">
    </body>
</html>

当我尝试将 HTML 内容插入到 FireFox 的可编辑区域时,上面的代码总是抛出错误,但它在 chrome 中运行良好。

我的FF版本:18.0.1

4

1 回答 1

0
   <div contenteditable="true">
        <ys_content ><!-- ~Client References -->
            <font size="2" face="Arial, Helvetica, sans-serif" color="#000000"><strong>More information coming soon...</strong> </font> 
        <!-- ~/Client References -->
        </ys_content>
    </div>

您的包装器 div 应设置为 contenteditable="true"

于 2013-02-01T13:09:49.893 回答