Javascript 如何在事件jquery中钩住并运行函数

Javascript 如何在事件jquery中钩住并运行函数,javascript,jquery,Javascript,Jquery,我如何在javascript/jquery中设置特定的函数,以便在特定事件中(比如wordpress操作钩子的工作方式)钩住特定的函数 基本代码 $('body').on('click', '[data-modal]', function() { var dis = $(this).data('modal'); // how can I hook something in here from outside this file $('#'+dis).addClass('i

我如何在javascript/jquery中设置特定的函数,以便在特定事件中(比如wordpress操作钩子的工作方式)钩住特定的函数

基本代码

$('body').on('click', '[data-modal]', function() {
    var dis = $(this).data('modal');
    // how can I hook something in here from outside this file
    $('#'+dis).addClass('is-active');
    // I also want to hook and run a function in here without directly calling them
});
下面是我想要达到的目标

$('body').on('click', '[data-modal]', function() {
    var dis = $(this).data('modal');

    trigger('before_open_' + dis); // I don't know what method to use here

    $('#'+dis).addClass('is-active');

    trigger('after_open_' + dis); // I don't know what method to use here
});

// I don't also know how to properly initialize the event
$(document).on('before_open_classes_pop', function() {
    console.log( $(this).data('modal') );
});
任何帮助都将不胜感激

创建第一个

现在调用这些事件作为

$('body').on('click', '[data-modal]', function() {
    var dis = $(this).data('modal');
    $(this).trigger('before_open'); 
    $('#'+dis).addClass('is-active');
    $(this).trigger('after_open');
});

wordpress动作钩这是什么意思?除了调用一个方法或触发一个自定义事件之外,您能准确地指定您想要什么吗?如果您想添加您自己的自定义事件,请检查此项。谢谢,这正是我想要的,我最终像这样做了
$(this).trigger('before_open'+dis,[$(this),dis]):)
$( "[data-modal]" ).on( "after_open", function(){
   var dis = $(this).modal();
   //logic to handle the after open event for a specific dis here
});
$('body').on('click', '[data-modal]', function() {
    var dis = $(this).data('modal');
    $(this).trigger('before_open'); 
    $('#'+dis).addClass('is-active');
    $(this).trigger('after_open');
});