我有点击这个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就绪而不是单击时触发此操作?
答案 0 :(得分: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');
});
答案 1 :(得分: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);
});