我正在使用zebra使用 jquery 1.12.4 (Wordpress) 的工具提示插件
我收到$.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/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="79031c1b0b18260d1616150d10090a394b5749574c" rel="noreferrer noopener nofollow">[email protected]</a>/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>
最佳答案
我有两种解决方法,但由于我对 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)也使用 $ 那么这可能会阻止其他脚本工作。
关于jquery - $.Zebra_Tooltips 不是构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57614314/