0

我有这个在点击时调用的 jQuery,

$("#overflow-cntr img").click(function(){
            $this = $(this);
            $("#bigpic-cntr canvas").remove();  
            $("#bigpic-cntr #bigpic").css("display", "block");
            window.setTimeout(function(){
                EFFECTS[$this.attr("id")]();
                }, 30);
        });

我如何在 DOM 就绪而不是点击时触发它?

4

2 回答 2

3
$(document).ready(function(){
    // bind the event and then trigger it immediately
    $("#overflow-cntr img").click(function(){
        $this = $(this);
        $("#bigpic-cntr canvas").remove();  
        $("#bigpic-cntr #bigpic").css("display", "block");
        window.setTimeout(function(){
            EFFECTS[$this.attr("id")]();
            }, 30);
    }).trigger('click');
});
于 2012-06-21T23:06:43.717 回答
0

将函数放在 $(document).ready() 中而不是 click() 中:

$(document).ready(function () {
    $this = $("#overflow-cntr img");
        $("#bigpic-cntr canvas").remove();  
        $("#bigpic-cntr #bigpic").css("display", "block");
        window.setTimeout(function(){
            EFFECTS[$this.attr("id")]();
            }, 30);
});
于 2012-06-21T23:08:00.027 回答