1

我正在制作自己的所见即所得编辑器。但是我不能使用 execcommand 函数使任何文本变为粗体。我正在使用下一个代码:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <title>Untitled Document</title>
        <script type="text/javascript">
            function loadWysiwyg() {
                if(window.navigator.appName == "Microsoft Internet Explorer") {
                    reactioneditor.document.designMode = "on"; 
                } else {
                    document.getElementById('reactioneditor').contentDocument.designMode = "on"; 
                }
            }
            function make_bold() {
                document.getElementById("reactioneditor").contentWindow.document.execCommand("bold", false, null); 
            }
        </script>
    </head>

    <body onload="loadWysiwyg();">
        <iframe id="reactioneditor" style="border: 1px solid #CCC;width: 100%; height: 200px;"></iframe>
        <button id="makebold" onclick="make_bold();">Maak bold</button>
    </body>
</html>

我阅读了多个教程,但没有任何效果,我现在不知道如何修复它。

有谁能做到吗?

4

1 回答 1

3

您的确切代码适用于 IE、Firefox 和 Chrome。我在 iFrame 中写入了一些文本,选择了它,然后单击了按钮。这些是你正在采取的步骤吗?你有任何错误吗?

于 2010-03-02T19:12:31.853 回答