TinyMCE-如何添加一个按钮来包装带有标签的所选文本 [英] TinyMCE - How to add a button that wraps selected text with a tag
本文介绍了TinyMCE-如何添加一个按钮来包装带有标签的所选文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我当前正在使用TinyMCE,并且想添加一个自定义按钮,其工作方式如下:
I'm currently using TinyMCE and would like to add a custom button that works as follows:
- 用户在文本编辑器中突出显示文本
- 用户单击自定义按钮X
- 文本(dog狗)包裹有标签(dog狗)
关于是否可以做到的任何想法?我已经弄清楚了如何使自定义按钮插入文本,而不是自动换行...这是当前代码:
Any ideas on if this can be done? I've figured out how to make a custom button inject text, but not wrap text... Here is the current code:
// Add a custom button
ed.addButton('mybutton', {
title : 'My button',
'class' : 'MyCoolBtn',
image : 'MyCoolBtn.png',
onclick : function() {
// Add you own code to execute something on click
ed.focus();
ed.selection.setContent('<strong>Hello world!</strong>');
}
});
谢谢!
thanks!
推荐答案
ed.addButton('mybutton', {
title: 'My button',
class: 'MyCoolBtn',
image: 'MyCoolBtn.png',
onclick: function() {
// Add your own code to execute something on click
ed.focus();
ed.selection.setContent('<tag>' + ed.selection.getContent() + '</tag>');
}
});
这篇关于TinyMCE-如何添加一个按钮来包装带有标签的所选文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文