Javascript 事件回调未获取tinymce目标信息
我在一个页面上有两个Javascript 事件回调未获取tinymce目标信息,javascript,jquery,iframe,javascript-events,tinymce,Javascript,Jquery,Iframe,Javascript Events,Tinymce,我在一个页面上有两个tinymce实例,当它们被修改时,我想更新一个javascript对象,该对象最终保存到localStorage 当页面加载时,我可以从localstorage填充两个tinymce实例,但是当它们被更改时,我似乎无法向我的update处理程序传递适当的jQuery事件,其中包括event.target信息。我怀疑这是由于一个iframe,但我被难住了 在我的update回调中,我需要知道e.target和e.target.id,但它会传递一个不包含该信息的对象,如下所示:
tinymce
实例,当它们被修改时,我想更新一个javascript对象,该对象最终保存到localStorage
当页面加载时,我可以从localstorage
填充两个tinymce
实例,但是当它们被更改时,我似乎无法向我的update
处理程序传递适当的jQuery
事件,其中包括event.target
信息。我怀疑这是由于一个iframe
,但我被难住了
在我的update
回调中,我需要知道e.target
和e.target.id
,但它会传递一个不包含该信息的对象,如下所示:
{isTrusted: true, screenX: 953, screenY: 790, clientX: 298, clientY: 20…}
这里的问题是获取编辑器id。您可以使用以下方法获取它:
setup:function(ed){
ed.on("init",function(e){
console.log('target id:',e.target.id);
});
ed.on("click",function(e,f){
var editor_id = e.view.frameElement.id.slice(0, -4);
console.log('editor_id:', editor_id);
// or much easier using ed.id
editor_id = ed.id;
// if you want to address the editor body you can use ed.getBody()
var my_editor = tinymce.get(editor_id);
// update(e);
});
},
要了解一个活生生的例子,请参阅我创建的tinymce小提琴:谢谢Thariama。这让我走上了正确的道路。我最终不得不这样做:更新(jQuery.Event(“mce_edit”,{target:$(e.view.frameElement.closest(“section”))[0]});很高兴能帮忙
setup:function(ed){
ed.on("init",function(e){
console.log('target id:',e.target.id);
});
ed.on("click",function(e,f){
var editor_id = e.view.frameElement.id.slice(0, -4);
console.log('editor_id:', editor_id);
// or much easier using ed.id
editor_id = ed.id;
// if you want to address the editor body you can use ed.getBody()
var my_editor = tinymce.get(editor_id);
// update(e);
});
},