问题
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