为什么这有效:
JS
$(gallery_1 + " .gallery_comandi #next").click(function avanti_gallery() {
contatore ++;
if (contatore > tot_immagini) {
contatore = 1;
cambia_immagine ();
}
else { cambia_immagine ();
};
});
这不是吗?第二个 cose 执行该函数。为什么?难道不应该通过像 avanti_gallery() 这样的命令启动吗?
JS
function avanti_gallery() {
contatore ++;
if (contatore > tot_immagini) {
contatore = 1;
cambia_immagine ();
}
else { cambia_immagine ();
};
};
$(gallery_1 + " .gallery_comandi #next").click(avanti_gallery());
最佳答案
您传递的是结果,而不是对函数的引用。
试试这个
$(gallery_1 + " .gallery_comandi #next").click(avanti_gallery);
关于javascript - 函数命名和启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20043515/