Javascript tinymce-是否可以从工具栏外部调用自定义插件函数?
嗯。我知道以前可能有人问过这个问题: 但我的问题是,如何从外部按钮而不是工具栏按钮调用插件函数 我添加了一个自定义插件:Javascript tinymce-是否可以从工具栏外部调用自定义插件函数?,javascript,tinymce-4,Javascript,Tinymce 4,嗯。我知道以前可能有人问过这个问题: 但我的问题是,如何从外部按钮而不是工具栏按钮调用插件函数 我添加了一个自定义插件: tinymce.PluginManager.add('example', function(e) { function customfunction(){ e.focus(true); alert('Hello TinyMce'); } }
tinymce.PluginManager.add('example', function(e) {
function customfunction(){
e.focus(true);
alert('Hello TinyMce');
}
}
);
我从其他函数调用这个customfunction
,当我点击Custom按钮时调用这个函数。
像这样:
function clickme()
{
tinymce.get('textareaid').plugins.example.customfunction();
}
按钮:
<button onclick="clickme()" >Custom Button</button>
自定义按钮
但它对我不起作用
这样调用自定义插件函数
对吗
我遗漏了什么吗?您的函数存储在
tinymce.PluginManager.items[0]
检查dom可以看到该函数。尝试提醒它一种可能是在工具栏中添加一个具有唯一ID的按钮
,并调用该按钮的单击事件。该插件如下所示:
tinymce.PluginManager.add('example', function(e) {
function customfunction() {
e.focus(true);
alert('Hello TinyMce');
}
e.addButton('testButton', {
id: "testButton",
text: 'Example',
icon: false,
onclick: function() {
// calls the custom function
customfunction();
}
});
}
);
tinymce.init({
selector: "textarea",
plugins: "example",
// show the button
toolbar: "testButton undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"
});
然后初始化tinymce编辑器,如下所示:
tinymce.PluginManager.add('example', function(e) {
function customfunction() {
e.focus(true);
alert('Hello TinyMce');
}
e.addButton('testButton', {
id: "testButton",
text: 'Example',
icon: false,
onclick: function() {
// calls the custom function
customfunction();
}
});
}
);
tinymce.init({
selector: "textarea",
plugins: "example",
// show the button
toolbar: "testButton undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"
});
最后调用按钮单击事件:
function clickme()
{
document.getElementById("testButton").click();
}
不要使用添加过滤器
。tinymce小提琴的完整代码:
<script type="text/javascript">
tinymce.PluginManager.add('example', function(e) {
function customfunction() {
e.focus(true);
alert('Hello TinyMce');
}
e.addButton('testButton', {
id: "testButton",
text: 'Example',
icon: false,
onclick: function() {
customfunction();
}
});
}
);
tinymce.init({
selector: "textarea",
plugins: "example",
toolbar: "testButton undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"
});
//add_filter('mce_external_plugins', 'example');
function clickme()
{
document.getElementById("testButton").click();
}
</script>
<form method="post" action="">
<textarea name="content" id="textareaid"></textarea>
</form>
<button onclick="clickme();" >abc</button>
tinymce.PluginManager.add('example',函数(e){
函数customfunction(){
e、 聚焦(真);
警报(“你好TinyMce”);
}
e、 addButton('testButton'{
id:“测试按钮”,
文本:“示例”,
图标:false,
onclick:function(){
自定义函数();
}
});
}
);
tinymce.init({
选择器:“文本区域”,
插件:“示例”,
工具栏:“testButton undo redo | styleselect |粗体斜体| alignleft aligncenter alignright alignjustify | bullist numlist outdent缩进|链接图像”
});
//添加_过滤器(“mce_外部_插件”,“示例”);
函数clickme()
{
document.getElementById(“testButton”)。单击();
}
abc