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

走远了吗. 提交于 2019-12-02 04:06:52

问题


I looked at http://api.jquery.com/trigger/ and the examples did not answer my question. I am looking at some code and would like to know what this block of code is doing.

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

Specifically, what does the colon inside of that trigger function do? For complete context, here is what filter is (I assume that the 'filter' inside of the trigger function refers to that filter object):

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();
    }
};

回答1:


The colons specifies custom events, essentially creating namespaces for events you can call later without overriding default events or having to create multiple listeners on the same event.

You can find more information here: https://learn.jquery.com/events/introduction-to-custom-events/



来源:https://stackoverflow.com/questions/40119808/what-does-colon-mean-in-jquery-when-used-inside-of-trigger

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