在.trigger中使用时,冒号在jQuery中是什么意思?

What does colon mean in jQuery when used inside of .trigger?

本文关键字:jQuery 是什么 意思 trigger      更新时间:2023-09-26

我看了http://api.jquery.com/trigger/,这些例子并没有回答我的问题。我正在看一些代码,想知道这个代码块是做什么的。

$(document).on('click', '#SubmitQuery', function(event) {
            event.preventDefault();
            $(document).trigger('filter:submit');
        });

具体来说,触发器函数中的冒号是做什么的?对于完整的上下文,下面是过滤器是什么(我假设触发器函数中的'filter'指的是那个过滤器对象):

var filter = {
    init: function() {
        $(document).on('keypress', '#Filter', debounce(function(event) {
            if (event.keyCode == 13) {
                $(document).trigger('filter:text');
            }
        }, 300));
        $(document).on('click', '#ClearFilter', function(event) {
            event.preventDefault();
            $('#FilterText').val('');
            $('#FilterText').focus();
            $(document).trigger('filter:clear');
        });
        $(document).on('change', '.filterSection [type=checkbox]', function(event) {
            var group = $(this).parents('[data-filter-group]').attr('data-filter-group');
            var $checkboxes = $('[data-filter-group=' + group + '] [type=checkbox]');
            if ($checkboxes.length > 0) {
                if ($checkboxes.filter(':checked').length === 0) {
                    $(this).prop('checked', true);
                }
            }
        });
        $(document).on('click', '#SubmitQuery', function(event) {
            event.preventDefault();
            $(document).trigger('filter:submit');
        });
        $("#Filter").focus();
    }
};

冒号指定自定义事件,本质上是为以后可以调用的事件创建名称空间,而无需覆盖默认事件或必须为同一事件创建多个侦听器。

您可以在这里找到更多信息:https://learn.jquery.com/events/introduction-to-custom-events/