我正在使用jQuery1.12.4 (Wordpress)的zebra工具提示插件
我得到了$.Zebra_Tooltips is not a constructor错误。
下面是我的代码:
new jQuery.Zebra_Tooltips($('.zebra_tooltips'), {
'animation_speed':50,
'animation_offset':10,
'hide_delay':0,
'show_delay':0
});<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/zebra_tooltips@2.0.5/dist/css/default/zebra_tooltips.min.css">
<script src="https://cdn.jsdelivr.net/npm/zebra_tooltips@latest/dist/zebra_tooltips.min.js"></script>
<p>
<a href="javascript: void(0)"
class="zebra_tooltips"
title="Zebra Tooltips is a lightweight and highly configurable jQuery tooltips plugin">
Over here!</a>
</p>
发布于 2020-06-27 21:00:21
我有两个变通方法,但由于我对jQuery了解不多,我不确定哪一个是最好的,也不知道它们是否都是“安全的”。Zebra_tooltips不是为在Wordpress中使用而编写的。
在脚本中,它们将所有代码包含在:
(function($) {
})($);但在Wordpress中,'$‘并不意味着'jQuery’,因为Wordpress已经抑制了这一点(如果我在技术上不正确,很抱歉)
因此,Zebra_tooltips脚本不知道最后一个($)表示jQuery
解决方案1
编辑Zebra_tooltips脚本,以便最后一行是
})(jQuery);而不是
})($);这意味着你将不得不对Zebra_tooltips脚本进行自己的“缩小”,如果Zebra_tooltips有更新,你将不得不重做你的编辑。
解决方案2
添加:
var $=jQuery.noConflict();添加到您自己的脚本中,然后再调用Zebra_tools
这告诉Zebra_tools (和Wordpress) '$‘的意思是jQuery。
我在这里看到的一个问题是,如果任何其他类型的脚本(不是jQuery)也在使用$,那么这可能会使其他脚本停止工作。
https://stackoverflow.com/questions/57614314
复制相似问题