gpt4 book ai didi

jquery - 使用 jquery 触发就绪函数的最短方法

转载 作者:行者123 更新时间:2023-12-01 02:57:14 24 4
gpt4 key购买 nike

这么简单的问题,我有这个功能......

galleryAjax();

我想在文档准备好时启动它。但目前我是这样写的......

jQuery(document).ready(function($) {
galleryAjax();
});

这似乎有点长,我想知道是否有一种简短的写法。

谢谢
乔什

最佳答案

您可以直接将函数传递给 jQuery:

$(galleryAjax);

来自.ready documentation :

All three of the following syntaxes are equivalent:

$(document).ready(handler)
$().ready(handler) (this is not recommended)
$(handler)

当然,如果你想在 DOM 上执行更多函数,那么传递匿名函数是有意义的:

$(function() {
galleryAjax();
// other functions are called here
});

关于jquery - 使用 jquery 触发就绪函数的最短方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18270832/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com