How to insert custom html tag using YUI Editor

送分小仙女□ 提交于 2019-12-23 04:11:20

问题


I've got YUI set up and working. I've created a custom button and it shows up fine. What I would like that button to do is wrap selected text with my own custom 'span' tags, just like clicking the 'bold' button wraps selected text with 'strong' / 'bold' tags.

Does anyone have any examples they could point to to make this work?


回答1:


Discovered the solution for myself, so I'm posting so others may see as well. :)

First, a BIG thanks to MK_Dev for inspiration from his similar question asked back in April. Here is the all the code that's needed for my problem (above):

this.toolbar.on('mycustombuttonClick', function() {
        var sSelection = this._getSelection();
        var sNewElt = '<span class="testhere">' + sSelection + '</span>';
        this.execCommand('inserthtml', sNewElt);
        return false;
    }, this, true);

Note that this assumes that the button that's inserting the html is on the toolbar.



来源:https://stackoverflow.com/questions/1717094/how-to-insert-custom-html-tag-using-yui-editor

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