TinyMCE自定义工具栏menuItem点击触发所有父item的点击事件
TinyMCE custom toolbar menuItem click triggers click events of all parent items
我正在像这样向我的 tinyMCE 添加自定义工具栏按钮
tinyMCE.init({
mode: "specific_textareas",
editor_selector: "mceEditor",
width: 600,
toolbar_items_size: "small",
plugins: ["advlist autolink lists link image charmap print preview anchor","searchreplace visualblocks code fullscreen","insertdatetime media table contextmenu paste "],
toolbar: "undo redo | styleselect | bullist numlist outdent indent | link image | stats ",
setup: function (editor) {
editor.addButton('stats',{
text: 'Stats',
type: 'menubutton',
icon: false,
menu: [
{
text: 'item1',
selectable: 'false',
classes: 'noselect',
onclick: function () { editor.execCommand('mceInsertContent', false, '{rootValue}');},
menu: [
{
text: 'item1.1',
selectable: 'false',
classes: 'noselect',
onclick: function () { editor.execCommand('mceInsertContent', false, '{midValue}');},
menu: [
{
text: 'item1.1.1',
selectable: 'false',
classes: 'noselect',
onclick: function () { editor.execCommand('mceInsertContent', false, '{leafValue}');},
},
]
},
]
},
]
});}});
所以我的按钮是一个有子菜单的菜单,那些子菜单可以有子菜单等等,所以我有多个嵌套的子菜单,每个子菜单都有一个 onclick 函数,可以将一些文本插入到编辑器中。我遇到的问题 运行 是,当我单击最里面的按钮时,它会触发从根开始的树路径上的所有 onclick 事件。所以如果我点击应该插入 {leafValue} 的按钮,它会插入这个
{leafValue}{midValue}{rootValue}
显然我只想在这里插入 leafValue。这是一个已知的 tinyMCE 问题吗?有人知道我该如何解决它吗?
可以使用preventDefault()
吗?
onclick:function (evt) {
editor.execCommand('mceInsertContent', false, '{leafValue}');
evt.preventDefault();
}
MDN:http://api.jquery.com/event.preventdefault/#event-preventDefault
我正在像这样向我的 tinyMCE 添加自定义工具栏按钮
tinyMCE.init({
mode: "specific_textareas",
editor_selector: "mceEditor",
width: 600,
toolbar_items_size: "small",
plugins: ["advlist autolink lists link image charmap print preview anchor","searchreplace visualblocks code fullscreen","insertdatetime media table contextmenu paste "],
toolbar: "undo redo | styleselect | bullist numlist outdent indent | link image | stats ",
setup: function (editor) {
editor.addButton('stats',{
text: 'Stats',
type: 'menubutton',
icon: false,
menu: [
{
text: 'item1',
selectable: 'false',
classes: 'noselect',
onclick: function () { editor.execCommand('mceInsertContent', false, '{rootValue}');},
menu: [
{
text: 'item1.1',
selectable: 'false',
classes: 'noselect',
onclick: function () { editor.execCommand('mceInsertContent', false, '{midValue}');},
menu: [
{
text: 'item1.1.1',
selectable: 'false',
classes: 'noselect',
onclick: function () { editor.execCommand('mceInsertContent', false, '{leafValue}');},
},
]
},
]
},
]
});}});
所以我的按钮是一个有子菜单的菜单,那些子菜单可以有子菜单等等,所以我有多个嵌套的子菜单,每个子菜单都有一个 onclick 函数,可以将一些文本插入到编辑器中。我遇到的问题 运行 是,当我单击最里面的按钮时,它会触发从根开始的树路径上的所有 onclick 事件。所以如果我点击应该插入 {leafValue} 的按钮,它会插入这个
{leafValue}{midValue}{rootValue}
显然我只想在这里插入 leafValue。这是一个已知的 tinyMCE 问题吗?有人知道我该如何解决它吗?
可以使用preventDefault()
吗?
onclick:function (evt) {
editor.execCommand('mceInsertContent', false, '{leafValue}');
evt.preventDefault();
}
MDN:http://api.jquery.com/event.preventdefault/#event-preventDefault