gpt4 book ai didi

已经使用 jQuery 对象的站点上的 jquery noConflict

转载 作者:行者123 更新时间:2023-12-01 04:54:31 25 4
gpt4 key购买 nike

我们有一些代码被引入并在许多网站上使用。我无法控制目标网站。

我们一直在使用 JQuery.noconflict() 来阻止我们的代码影响网站,但我们有一个已经在使用 JQuery 的目标,我不知道如何解决这个问题......

基本上,当我们的代码被拉入网站上的一些 Jquery 功能时,就会中断。

这是我们造成问题的 Jquery 的一个片段..

jQuery(function(){
jQuery('#superfish-4').supersubs({minWidth: 12, maxWidth: 27, extraWidth: 1}).superfish({
animation: {opacity:'show'},
speed: 'fast',
autoArrows: false,
dropShadows: true}).supposition().find('ul').bgIframe({opacity:false});
});

当包含我们的代码时,我们会收到以下错误:

未捕获类型错误:对象 [object Object] 没有方法“supersubs”

以下是我们的 Jquery 的一些示例。

<script src="jquery-latest.min.js" type="text/javascript"></script> 
<script>jQuery.noConflict();
jQuery(document).ready(function() {
jQuery('head').append('<link rel="stylesheet" href="cssfilehere" type="text/css" />');
jQuery.get('htmlfilehere', function(data) { jQuery('div.fdmediabar-65144924').html(data); }); });
</script> <div id="idhere" class="classhere"></div>

我已经删除了类名和 URL,因为这是一个客户端项目。

我不确定如何以不同的方式引用 JQuery 对象?

最佳答案

如果您调用.noConflict(true) ( documentation ):

If for some reason two versions of jQuery are loaded (which is not recommended), calling $.noConflict(true) from the second version will return the globally scoped jQuery variables to those of the first version.

然后您可以将 jQuery 覆盖为之前加载的版本。

您必须保留自己对 jQuery 的引用并使用它。请参阅this for more discussion .

关于已经使用 jQuery 对象的站点上的 jquery noConflict,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15638296/

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