2010-08-17 96 views

回答

1

这似乎切换文档对象的designMode属性,并将其设置为 “开” 与此功能:

function tryEnableDesignMode(iframe, doc, callback) { 
    try { 
     iframe.contentWindow.document.open(); 
     iframe.contentWindow.document.write(doc); 
     iframe.contentWindow.document.close(); 
    } catch(error) { 
     console.log(error) 
    } 
    if (document.contentEditable) { 
     iframe.contentWindow.document.designMode = "On"; 
     callback(); 
     return true; 
    } 
    else if (document.designMode != null) { 
     try { 
      iframe.contentWindow.document.designMode = "on"; 
      callback(); 
      return true; 
     } catch (error) { 
      console.log(error) 
     } 
    } 
    setTimeout(function(){tryEnableDesignMode(iframe, doc, callback)}, 250); 
    return false; 
} 
+0

谢谢你非常感谢你的帮助 – john 2010-08-17 17:02:47

1

你所指的是所谓的所见即所得。

制作WYSIWYG的基本原理是拥有一个iframe,其属性为designMode = true。基本上,这是你如何拥有一个textarea的外观和感觉,但有额外的功能。

欲了解更多信息,你可以看看那些教程:
- http://www.emirplicanic.com/javascript/cross-browser-textarea-editor.php
- https://developer.mozilla.org/en/Rich-Text_Editing_in_Mozilla
- http://msdn.microsoft.com/en-us/library/ms537834(VS.85).aspx

或者以关键字 “所见即所得的JavaScript教程” 在谷歌搜索。

相关答案
- javascript Rich Text Editors

+0

谢谢HoLyVieR, – john 2010-08-17 16:30:53