多次调用同一Jquery文件

多次调用同一Jquery文件,jquery,Jquery,我有多个在我的站点上使用jquery的实例(如图像滑块和导航),但如果我不多次调用jquery,它们将无法工作 例如,除非我调用脚本两次,否则下面的2个代码片段将无法工作。请帮忙。(我的页面上有更多的jquery调用以及调用不同的库)我不能只调用一次最新的库就可以完成吗?我试过了,但没有成功 <!--menu --> <script type="text/javascript" src="js/jquery.min.js"></script> <link

我有多个在我的站点上使用jquery的实例(如图像滑块和导航),但如果我不多次调用jquery,它们将无法工作

例如,除非我调用脚本两次,否则下面的2个代码片段将无法工作。请帮忙。(我的页面上有更多的jquery调用以及调用不同的库)我不能只调用一次最新的库就可以完成吗?我试过了,但没有成功

<!--menu -->
<script type="text/javascript" src="js/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/newnav.css" />
<script type="text/javascript" src="js/navdoublecolumn.js"></script>
<script>
<!--
ddmegamenu.docinit({
    menuid:'solidmenu',
    dur:0, 
    easing:'easeInOutCirc' //<--no comma after last setting
})
// -->
</script>



<!-- slide -->
<script type="text/javascript" src="js/jquery.min.js"></script>
<script src="js/jquery.tabSlideOut.v1.3.js"></script>

<script type="text/javascript">
$(function(){
    $('.slideout1').tabSlideOut({
        tabHandle: '.slideouthandle1',             //class of the element that will become your tab
        pathToTabImage: 'images/slideouttab_chat.jpg',//path to the image for the tab //Optionally can be set using css
        imageHeight: '150px',                     //height of tab image           //Optionally can be set using css
        imageWidth: '40px',                       //width of tab image            //Optionally can be set using css
        tabLocation: 'left',                      //side of screen where tab lives, top, right, bottom, or left
        speed: 200,                               //speed of animation
        action: 'click',                          //options: 'click' or 'hover', action to trigger animation
        topPos: '215px',                          //position from the top/ use if tabLocation is left or right
        leftPos: '20px',                          //position from left/ use if tabLocation is bottom or top
        fixedPosition: true                       //options: true makes it stick(fixed position) on scroll
    });

});
</script>

$(函数(){
$('.slideout1').tabSlideOut({
tabHandle:'.slideouthandle1',//将成为选项卡的元素的类
pathToTabImage:'images/slideouttab_chat.jpg',//选项卡的图像路径//也可以使用css设置
imageHeight:'150px',//选项卡图像的高度//也可以使用css设置
imageWidth:'40px',//选项卡图像的宽度//可以选择使用css设置
tabLocation:'左',//选项卡所在屏幕的一侧,顶部、右侧、底部或左侧
速度:200,//动画速度
操作:'单击',//选项:'单击'或'悬停',触发动画的操作
topPos:'215px',//从顶部定位/如果tabLocation为左或右,则使用
leftPos:'20px',//从左开始定位/如果tabLocation为底部或顶部,则使用
fixedPosition:true//选项:true使其在滚动上保持(固定位置)
});
});

我预计
navdoublecolumn.js
中的某些内容会覆盖或破坏jQuery功能。通过第二次包含jQuery,您重新定义了方法/变量,从而恢复了
navdoublecolumn.js
已经破坏的功能


当您删除第二个jQuery包含项时,通过查看javascript控制台错误输出,您可能会得到一条破坏性的线索。

当您使用
jQuery.noconflict()
时,请使用以下命令:

jQuery(function($){
    $('.slideout1').tabSlideOut({
        tabHandle: '.slideouthandle1',             //class of the element that will become your tab
        pathToTabImage: 'images/slideouttab_chat.jpg',//path to the image for the tab //Optionally can be set using css
        imageHeight: '150px',                     //height of tab image           //Optionally can be set using css
        imageWidth: '40px',                       //width of tab image            //Optionally can be set using css
        tabLocation: 'left',                      //side of screen where tab lives, top, right, bottom, or left
        speed: 200,                               //speed of animation
        action: 'click',                          //options: 'click' or 'hover', action to trigger animation
        topPos: '215px',                          //position from the top/ use if tabLocation is left or right
        leftPos: '20px',                          //position from left/ use if tabLocation is bottom or top
        fixedPosition: true                       //options: true makes it stick(fixed position) on scroll
    });

});

为了澄清,为什么每次都需要打电话?我肯定没有。有人能帮我解决这个问题吗?它不应该每次调用,每个html页面调用一次。。。唯一的原因可能是您重新定义了
$
或使用了
jQuery.noconflict()
不知道这是否重要,但我使用的是一个CMS,它在fly上注入了head部分,也就是我调用的地方,使事情变得不起作用,这意味着您应该将jQuery函数调用为
jQuery()
,而不是
$()
那么,你是说在这种情况下,我别无选择,只能再次调用它吗?不。我是说,如果你不再调用它,你就有机会找出错误是什么。你可以使用noconflict来判断错误是什么,而不是立即向下投票。