2010-03-02 99 views
0

我正在制作自己的所见即所得编辑器。但是我不能用execcommand函数使任何文本粗体。我正在使用下面的代码:ifc的exec命令不起作用

<!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> 

我参考了多个教程,但没有效果,我现在不怎么修复它。

有没有人可以?

回答

2

您的确切代码适用于IE,Firefox和Chrome。我在iFrame中写了一些文字,选中它,然后点击按钮。那些你正在采取的步骤?你有什么错误吗?

+0

omg,我很愚蠢。尽管execcommand适用于iframe中的整个文本(无需选择它),谢谢你帮助我! – Timo 2010-03-02 19:26:34

+0

没问题,我认为这可能很简单。通常'execCommand'将执行在用户选择的文本上传递给它的动作。 – rosscj2533 2010-03-02 19:33:37