以编程方式从WYSIHTML5编辑器中检索内容

时间:2012-06-11 19:07:05

标签: javascript jquery editor wysiwyg wysihtml5

如何以编程方式从WYSIHTML5编辑器中检索内容? 假设编辑器实例化为:

var editor = new wysihtml5.Editor
(
   $(this.el).find('textarea').get(0),
   {
      toolbar:      "toolbar",
      parserRules:  wysihtml5ParserRules
   }
);

我想在blur事件

上获取编辑的内容
editor.on
(
   "blur",
   function()
   {
      //what here?
   }
);

2 个答案:

答案 0 :(得分:11)

使用API​​要好得多 editor.getValue()

(@ dalen在上面的评论中提到了这一点)

答案 1 :(得分:5)

这是如何(在这里使用jQuery):

$('iframe').contents().find('.wysihtml5-editor').html();

要查找文字,请使用text()代替html()

供参考:

在你的应用程序中,你不需要jQueryify bookmarklet,我用它在该演示页面上注入jQuery,这样我就可以用它来获取编辑器的价值。


话虽如此,通常应该在该编辑器中使用一些内置方法来获取当前值,您应该查看文档:)

相关问题