2010-08-17 98 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