iframe如何?contentWindow.文件.execCommand工作?

pin*_*ong 5 html jquery plugins

我试图找出这个文本编辑器如何工作,iv扫描脚本,似乎无法理解它.

首先,这是演示的链接

我无法理解的是当你点击触发这个的粗体按钮时

 $('.bold', tb).click(function(){ formatText(iframe, 'bold');return false; });
Run Code Online (Sandbox Code Playgroud)

然后它被发送到formatText函数,这就是我迷失的地方,因为他们没有提到<strong></strong>在textarea中为文本添加标签,我真的很想知道它是如何工作的,谢谢.

Hus*_*ein 5

function formatText(iframe, command, option) {
    iframe.contentWindow.focus();
    try{
        iframe.contentWindow.document.execCommand(command, false, option);
    }catch(e){console.log(e)}
    iframe.contentWindow.focus();
Run Code Online (Sandbox Code Playgroud)

formatText不是默认的jQuery函数.我从编辑器的js源代码中获取了上述内容.它首先关注的是文本所在的iframe区域.你不是真的在textarea字段中输入,而是在iframe contentEditable div中输入,<div contentEditable="true"></div>因为textarea不支持富文本编辑.然后该函数发出contentEditable exexCommand以使所选文本变为粗体.

您可以在http://help.dottoro.com/larpvnhw.php查看所有execCommands的列表