access the bootstrap-wysihtml5 editor object

て烟熏妆下的殇ゞ 提交于 2019-12-10 17:23:20

问题


I'm trying to acces into an bootstrap-wysihtml5 editor object. I'm doing this by this way:

$(document).ready(function () {
     $('.someLink').live('click', function () {
          var wysihtml5Editor = $('#textarea').wysihtml5().editor;
          console.log('wysihtml5Editor: '+wysihtml5Editor);
          wysihtml5Editor.composer.commands.exec("bold");
     });
});

Chrome console returns:

> wysihtml5Editor: undefined
> Uncaught TypeError: Cannot read property 'composer' of undefined

So, the point is.

Which is the way to acces into an wysihtml5 object?

The point of everything is insert some html code into my textarea.


回答1:


Try this:

$(document).ready(function () {
   $('.someLink').live('click', function () {
     $('#textarea').wysihtml5();
     var wysihtml5Editor = $("#textarea").data("wysihtml5").editor;
     console.log('wysihtml5Editor: '+wysihtml5Editor);
     // The following is important since wysihtml5 is initialized asynchronously
     wysihtml5Editor.observe("load", function() {
       wysihtml5Editor.composer.commands.exec("bold");
     });
   });
});


来源:https://stackoverflow.com/questions/10092792/access-the-bootstrap-wysihtml5-editor-object

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!