如何使用YUI编辑器插入自定义html标记 [英] How to insert custom html tag using YUI Editor
问题描述
我已经设置了YUI并且正在工作。我已经创建了一个自定义按钮,它显示正常。我想要按钮做的是用我自己的自定义'span'标签包装所选文本,就像点击'粗体'按钮用'strong'/'bold'标签包装所选文本一样。
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?
推荐答案
发现了解决方案我自己,所以我发帖,所以其他人也可以看到。 :)
Discovered the solution for myself, so I'm posting so others may see as well. :)
首先,感谢MK_Dev从他的类似问题在四月回复。以下是我的问题所需的所有代码(上图):
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);
请注意,这假设插入html的按钮位于工具栏上。
Note that this assumes that the button that's inserting the html is on the toolbar.
这篇关于如何使用YUI编辑器插入自定义html标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!