Function execution problems in delegate events and normal binding events

The

clipboard.png
code is as follows:

    $(".password").on("keydown", function(e) {
        if (e.keyCode === 13 && !e.ctrlKey) {
            e.preventDefault();
            $(".loading-btn").click(denlu());
        }
    })
    $(".loading-btn").click(function(){denlu()});

if $(".loading-btn") .click (function () {denlu ()}); written as $(".loading-btn") .click (denlu ()); page refresh will be performed directly, but not in $(".password"). On ("keydown", function (e) {}). Why? Please advise Thanks ()


first understand the jQuery event method: the
event method triggers an event that matches an element, or binds a function to an event of all matching elements.

combine your code
trigger:

$('.loading-btn').click(denlu());

bind function:

$(".loading-btn").click(function(){denlu()});

if it is triggered and is not placed in the callback (function) of an operation, it will be triggered when the current line of code is read, so
$('.loading-btn') .click (denlu ()); will immediately trigger $('. Loading-btn'). Click,
so denlu () in click () will also be executed as a function expression statement.

Menu