Javascript jQuery函数没有';无法定义
我想使用: 正如您在my上看到的,我将Javascript jQuery函数没有';无法定义,javascript,jquery,html,header,Javascript,Jquery,Html,Header,我想使用: 正如您在my上看到的,我将jquery.zoom.js作为jquery嵌入到页面的头部。但我仍然得到: Uncaught TypeError: jQuery(...).zoom is not a function at HTMLDocument.<anonymous> ((index):77) at i (jquery.js:2) at Object.fireWith [as resolveWith] (jquery.js:2) at Fu
jquery.zoom.js
作为jquery嵌入到页面的头部。但我仍然得到:
Uncaught TypeError: jQuery(...).zoom is not a function
at HTMLDocument.<anonymous> ((index):77)
at i (jquery.js:2)
at Object.fireWith [as resolveWith] (jquery.js:2)
at Function.ready (jquery.js:2)
at HTMLDocument.K (jquery.js:2)
我将非常感谢你的帮助!
亲切的问候我没有看到任何问题。看我给你做的例子
jQuery(函数(){
$('.img-wrapper-inner').zoom({});
});代码>
您在代码的第5行和第148行加载了两次jQuery。您在第6行加载jquery.zoom.js
,因此它存储在原始jquery
变量中。当您稍后重新加载jQuery时,它会替换变量,您将丢失jQuery.fn.zoom
去掉开头的行,在同一块中加载jquery.zoom.js
,再往下加载所有其他脚本。我刚刚尝试添加jquery版本,但出现了extend
所以建议尝试添加此库,然后检查
jQuery(文档).ready(函数(){
变量img=”https://radlvoo.de/wp-content/uploads/2017/02/Backfire_Pro_100_29_Petrol_MY2017.png";
jQuery('.img包装器内部').zoom({
网址:img
});
});代码>
在这里工作正常,代码中的其他内容导致了问题
var img=”https://radlvoo.de/wp-content/uploads/2017/02/Backfire_Pro_100_29_Petrol_MY2017.png";
$(“.img包装内部img”).attr(“src”,img);
$('.img包装内部').zoom({
网址:img,
回调:函数(){
//jQuery(this.colorbox({href:this.src});
}
});代码>
.img包装器内部{
宽度:200px;
高度:200px;
边框:1px实心#CCC;
}
.img包装内部img{
宽度:100%;
}
你是否在首页的第一页包含了js库?也许你可以在页脚处移动它以获得最佳性能,最早,在jQuery和jQueryZoom的上方是这样的:
在我想优化性能之前,我想让它工作。请在jQuery中按类名捕获处理程序,你应该使用点(
). 正如@Kashyap所说的那样。e、 gjQuery('.img wrapper-inner')
谢谢!我现在通过从WordPress注销jQuery并使用GoogleCDNjQuery修复了它。但现在我还有一个错误。这是一个(index):82未捕获类型错误:jQuery(…)。colorbox不是HTMLImageElement.callback((index):82)在HTMLImageElement.img.onload(jQuery.zoom.js:225)的函数。
无论您使用jQuery的WP还是CDN版本,只要在加载任何插件之前加载一次就行了。当我加载你的站点时,我没有看到这个错误,我必须做些什么来触发它吗?
<script>
jQuery(document).ready(function(){
var img ="<?php $src = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'full', false ); echo $src[0]; ?>";
jQuery('img-wrapper-inner').zoom({
url: img,
callback: function(){
jQuery(this).colorbox({href: this.src});
}
});
});
</script>