【发布时间】:2019-05-16 21:09:09
【问题描述】:
如何使用 JQuery 创建自定义按钮 tinymce 按钮?我需要 n 个“菜单项”按钮。在打开 tinymce 编辑器之前,将根据所选数据定义“n”。
我的按钮:
editor.addButton('addButtons', {
type: 'menubutton',
text: 'My button',
icon: false,
menu: [
{
text: 'Menu item 1',
onclick: function() {
editor.insertContent(' <strong>item1</strong> ');
}
}, {
text: 'Menu item 2',
onclick: function() {
editor.insertContent(' <strong>item2</strong> ');
}
}, {
text: 'Menu item 3',
onclick: function() {
editor.insertContent(' <strong>item3</strong> ');
}
}
]
});
我可以从使用 JQuery $("#totalButtons").val() 隐藏的输入类型中获取“n”值。如果 totalButtons 是 4,我需要 4 个项目按钮。是否有意义?有可能吗?
谢谢
更新代码:
var n = $('#total').val();
var menuItems = [];
tinymce.init({
selector: '#mytextareaTenant',
content_css: 'https://fonts.googleapis.com/css?family=Aguafina+Script|Alex+Brush|Bilbo|Condiment|Great+Vibes|Herr+Von+Muellerhoff|Kristi|Meddon|Monsieur+La+Doulaise|Norican|Nothing+You+Could+Do|Parisienne|Permanent+Marker|Sacramento|Yellowtail',
theme: 'modern',
menubar: false,
plugins: [
"print"
],
setup: function (editor) {
editor.on('init', function (e) {
renderEditorTenant();
for (var i=1; i<=n; i++){
var msg = ' <strong>#item' + i + '#</strong> ';
var obj = {
text: 'Menu item ' + i,
onclick: function() {
editor.insertContent(msg);
}
}
menuItems.push(obj);
}
});
【问题讨论】:
-
不,它只是说如何创建按钮。如果你看我的代码,我已经有了。我需要根据用户输入设置按钮的数量
标签: javascript jquery tinymce