Display alert when a button is clicked in CK Editor

六月ゝ 毕业季﹏ 提交于 2020-01-04 06:31:11

问题


How can I display an alert with ckeditor if a button is pressed?

Here's the code:

$(document).ready(function () {
      $(".cke_button__bold").click(function () {
          editor.on("CKEDITOR.cke_button__bold",CKEDITOR.cke_button_on);

          function handleAfterCommandExec(evt){
                var commandName = CKEDITOR.command.cke_button__bold;
                // For 'bold' commmand
                if (commandName == 'cke_button__on')
                {
                    alert("Bold button pressed!");

                }
         }
     });
});

回答1:


event delegation

Event delegation allows us to attach a single event listener, to a parent element, that will fire for all descendants matching a selector, whether those descendants exist now or are added in the future.

$(document).ready(function () {
      $(document).on('click','.cke_button__bold',function () {
         if($(this).hasClass('cke_button_on'))//checking for enable only
         {
           alert("Click event occure when only enable");
         }
     });
});

Updated DEMO



来源:https://stackoverflow.com/questions/27372292/display-alert-when-a-button-is-clicked-in-ck-editor

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