Why is this javascript function running without being called?

前端 未结 4 1410
暗喜
暗喜 2020-12-19 11:26
$(document).ready(SetupButtonClicks());

function SetupButtonClicks() {
    $(\'#btnJavaPHP\').click(DoPHPStuff());
}

function DoPHPStuff() {
    //stuff
}
<         


        
4条回答
  •  悲&欢浪女
    2020-12-19 11:56

    With the exception of a function declaration, a pair of parentheses following a function's identifier causes the function to execute. Examples:

    // function declaration; function not executed
    function SetupButtonClicks() {
    
    }
    
    // function executed
    SetupButtonClicks();
    
    // function not executed
    SetupButtonClicks;
    

提交回复
热议问题