[英]How to insert custom html tag using YUI Editor
I've got YUI set up and working. 我已经设置好YUI并开始工作。 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.
我希望该按钮执行的操作是使用我自己的自定义“ span”标签包裹所选文本,就像单击“ bold”按钮将所选文本包装为“ strong” /“ bold”标签一样。
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. 为我自己找到了解决方案,因此我正在发布,以便其他人也可以看到。 :)
:)
First, a BIG thanks to MK_Dev for inspiration from his similar question asked back in April . 首先,BIG非常感谢MK_Dev 在4月份提出的类似问题中的启发。 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. 请注意,这假定插入html的按钮在工具栏上。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.