问题
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