Bind onkeydown after TinyMCE is already initiated

守給你的承諾、 提交于 2019-12-24 04:15:09

问题


I like to bind the event onKeyDown after tinyMCE has already initiated for the site.

$('#content_ifr').keydown(...); doesn't work here. So how could it be done?


回答1:


Firstly your jQuery selector is invalid...it is looking for a tagName content_ifr which certainly can't exist. Assuming element has ID content_ifr use:

$('#content_ifr').keydown(...);

To call this after TinyMCE initialized use the TinyMCS oninit calback in your config object.

Reference docs: http://www.tinymce.com/wiki.php/Configuration:oninit

You can probably use jQuery event delegation to call your code any time without needing to call it in TinyMCE config using jQuery on() or delegate() methods

EDIT: If element is an Iframe which I suspect it is from the selector, you would need to use contents() method to bind keydown event within the iframe

http://api.jquery.com/on/

http://api.jquery.com/delegate/




回答2:


$('#'+your_editor_id + '_ifr').bind('keydown',function(){
    //do what you like here with the event
});



回答3:


You can write something like this:

$('content_ifr').bind('keydown',function(){
    //your code goes here
 });


来源:https://stackoverflow.com/questions/12880643/bind-onkeydown-after-tinymce-is-already-initiated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!