gpt4 book ai didi

jquery - 未捕获的 TypeError : $. backstretch 不是函数

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

我想在我的代码中添加 backstretch
这是脚本:

<script>
// To attach Backstrech as the body's background
jquery.backstretch("/form-3/assets/img/backgrounds/1.jpg");

// You may also attach Backstretch to a block-level element
jquery.(".foo").backstretch("/form-3/assets/img/backgrounds/1.jpg");

// If your element defines a background image with CSS, you can omit the argement altogether
//$(".foo").backstretch();

// Or, to start a slideshow, just pass in an array of images
jquery.(".foo").backstretch([
"/form-3/assets/img/backgrounds/1.jpg",
"/form-3/assets/img/backgrounds/2.jpg",
"/form-3/assets/img/backgrounds/1@2x.jpg"
], {duration: 4000});

</script>

//I have included the scripts here
<script src="/form-3/assets/js/jquery-1.11.1.min.js"></script>
<script src="/form-3/assets/js/jquery-1.11.1.js"></script>
<script src="/form-3/assets/bootstrap/js/bootstrap.min.js"></script>
<script src="/form-3/assets/js/jquery.backstretch.min.js"></script>

<script src="/form-3/assets/js/jquery.backstretch.js"></script>
<script src="/form-3/assets/js/scripts.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"> </script>

我想在打开此 html 页面时动态更改图像。但它说的是

Uncaught type error. $backstretch is not a function.

我们如何包含它?或者还有其他方法可以动态改变图片吗?

最佳答案

您在初始化插件后包含脚本,这是上述错误的实际原因。只需将所有脚本移到任何 js

之前
<script src="/form-3/assets/js/jquery-1.11.1.min.js"></script>
<script src="/form-3/assets/bootstrap/js/bootstrap.min.js"></script>
<script src="/form-3/assets/js/jquery.backstretch.min.js"></script>
<script src="/form-3/assets/js/jquery.backstretch.js"></script>
<script src="/form-3/assets/js/scripts.js"></script>

<script>
// To attach Backstrech as the body's background
jquery.backstretch("/form-3/assets/img/backgrounds/1.jpg");

// You may also attach Backstretch to a block-level element
jquery.(".foo").backstretch("/form-3/assets/img/backgrounds/1.jpg");

// If your element defines a background image with CSS, you can omit the argement altogether
//$(".foo").backstretch();

// Or, to start a slideshow, just pass in an array of images
jquery.(".foo").backstretch([
"/form-3/assets/img/backgrounds/1.jpg",
"/form-3/assets/img/backgrounds/2.jpg",
"/form-3/assets/img/backgrounds/1@2x.jpg"
], {duration: 4000});

</script>

不要包含对同一文件的多个引用,因为您已多次包含对 jquery-1.11.1.min.js 的引用。

而且我觉得这些行 jquery.(".foo") 必须是 jquery(".foo")jquery

之后没有 .

关于jquery - 未捕获的 TypeError : $. backstretch 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42129384/

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