gpt4 book ai didi

javascript - 即使按照正确的顺序,函数也没有定义?

转载 作者:行者123 更新时间:2023-12-03 01:07:05 25 4
gpt4 key购买 nike

我正在使用 lazyload与 jQuery 一起使用的函数。

我在我的 liga.js 文件中这样调用它:

lazyload();

现在,在该页面的页脚处,我有:

<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script src="code.jquery.com/ui/1.12.1/jquery-ui.min.js" ></script>
<script src="/includes/jquery.lazyload.min.js"></script>
<script src="/includes/liga.js"></script>

如您所见,我的liga.js 文件位于列表的最后。

我也尝试过像这样调用该函数:

$(document).ready(function(){
lazyload();
...

我不断收到错误:

ReferenceError: lazyload is not defined

这是为什么?

最佳答案

jQuery 包装器的语法是 $(selector).lazy() ...

$(function() {

$('.iam').lazy({

/* called before an element gets handled */
beforeLoad: function(element) {
var imageSrc = element.data('src');
console.log('image "' + imageSrc + '" is about to be loaded');
},

/* called after an element was successfully handled */
afterLoad: function(element) {
var imageSrc = element.data('src');
console.log('image "' + imageSrc + '" was loaded successfully');
},

/* called whenever an element could not be handled */
onError: function(element) {
var imageSrc = element.data('src');
console.log('image "' + imageSrc + '" could not be loaded');
},

/* called once all elements were handled */
onFinishedAll: function() {
console.log('finished loading all images');
}
});
});
<script src="//code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery.lazy/1.7.10/jquery.lazy.min.js"></script>

<img class="iam" data-src="http://www.ektoplazm.com/img/escape-into-the-mirror.jpg" width="640" height="640" />

关于javascript - 即使按照正确的顺序,函数也没有定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52347946/

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