admin管理员组

文章数量:1319007

How can I bind multiple events on tinymce such that those events e.g. click, keyup and change have the same handler function?

I am trying like this but the events are not firing.

tinymce.dom.Event.add(ed, 'click keyup change', function (ed, e) {
     // Handler here...                   
});

I also tried this where ed is my document

ed.bind('click keyup change', function (ed, e) {
     // Handler here...
});

but bind is not defined for tinymce. How can I get this working?

Thanks :)

How can I bind multiple events on tinymce such that those events e.g. click, keyup and change have the same handler function?

I am trying like this but the events are not firing.

tinymce.dom.Event.add(ed, 'click keyup change', function (ed, e) {
     // Handler here...                   
});

I also tried this where ed is my document

ed.bind('click keyup change', function (ed, e) {
     // Handler here...
});

but bind is not defined for tinymce. How can I get this working?

Thanks :)

Share Improve this question asked Mar 28, 2013 at 18:54 BerniceBernice 2,59211 gold badges45 silver badges75 bronze badges 2
  • 1 I'm not familiar with tinymce but you can create a function then pass it without () as callback. – Ricardo Lohmann Commented Mar 28, 2013 at 18:58
  • tinymce.dom.Event.add(ed, 'click', thefunction); tinymce.dom.Event.add(ed, 'keyup', thefunction); function thefunction(){ //whatever } – David Fregoli Commented Mar 28, 2013 at 19:00
Add a ment  | 

2 Answers 2

Reset to default 8
function myFunction(ed, e) {
    // do what you want
}

tinymce.dom.Event.add(ed, 'click', myFunction);
tinymce.dom.Event.add(ed, 'keyup', myFunction);
tinymce.dom.Event.add(ed, 'change', myFunction);

Make one callback function and pass it to each of them

I do not believe that tinymce gives you the ability to add multiple events at once.

For example:

callbackFn = function (ed, e) {
     // Handler here...                   
};
tinymce.dom.Event.add(ed, 'click', callbackFn );
tinymce.dom.Event.add(ed, 'keyup', callbackFn );
...

本文标签: javascriptBinding multiple eventsStack Overflow