我正在尝试在加载时调用 test() 函数。我就是这样做的:
if ($('.partical .sectionA').length) {
$(document).ready(function(){
test($(this));
});
}
test(something){...}
我发现在 If Else 语句中使用
ready()
方法很奇怪,我想知道这是否是一个好的做法,或者是否有更好的方法在页面加载时调用测试函数?
这是错误的做法。在标签工作之前它必须是内联的。那么准备时的
$(this)
是什么呢?
也许你的意思是
$(function(){
const $sectionA = $('.partical .sectionA');
if ($sectionA.length) test($sectionA);
});