0

我想知道在同一个 js 类型文件上多次使用下面的代码是否有任何意义,以及如果在另一个文档中使用它会做什么准备。

$(function () {
    //some code
});
$(function () {
    //some other code
    $(function () {
        //does this here make any sense?
    });
});
4

2 回答 2

3

$(function() { })是 的直接等价物$(document).ready(function() { });。因此,虽然第一个有意义,但第二个肯定没有。如果你知道它DOMContentLoaded已经触发了......你为什么要告诉 jQuery 再次测试?

于 2013-05-28T18:09:55.233 回答
2

多少次 $(function () {}); 可以在同一个 js 文件中的 jQuery 中使用吗?

技术上任意数量的时间。

但一个里面另一个没有任何意义

像这个没有任何意义

$(function () {
    //some other code
    $(function () {
        //does this here make any sense?
    });
});
于 2013-05-28T18:10:21.923 回答