如何解决这个 jQuery 插件冲突? [英] How do I solve this jQuery plugins conflict?

查看:29
本文介绍了如何解决这个 jQuery 插件冲突?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用两个不同的 jQuery 插件;一个用于新闻徽标,另一个用于水平文本滑块.

I am using two different jQuery plugins; one for news logo ticker and another for horizontal text slider.

但在单页中使用时只有一个在工作,可能是因为 jQuery 冲突.如果我评论第一个插件,第二个插件工作正常,反之亦然.

but only one of them is working at a time when when used in single page may be because of jQuery conflict.. If I comment first plugin second plugin works fine and vice verse.

代码如下:

<script type="text/javascript" src="js/jquery.js"></script>
    <script type="text/javascript" src="js/jquery.newsticker.js"></script>
    <script type="text/javascript">
        jQuery(document).ready(
            function()
            {
                jQuery("#news").newsTicker();
                jQuery("#development").newsTicker();                
            }
        );
    </script>
    <link href="css/style.css" rel="stylesheet" type="text/css">            
    <link rel="stylesheet" type="text/css" href="plugins/image_slider/css/sliderman.css" /> 


    <link type="text/css" href="css/humanity/jquery-ui-1.8.13.custom.css" rel="stylesheet" />   
    <script type="text/javascript" src="js/jquery-1.5.1.min.js"></script>
    <script type="text/javascript" src="js/jquery-ui-1.8.13.custom.min.js"></script>
    <script type="text/javascript">
        jQuery(function(){
            jQuery("#accordion").accordion({ header: "h3" });
        });
    </script>
    <link rel="stylesheet" href="css/news.css" type="text/css" media="screen">
    <script src="js/jcarousellite_1.0.1c4.js" type="text/javascript">  
</script>

谢谢!

推荐答案

  1. 仅仅添加 jQuery.noConflict(); 是不够的.您可能还需要用 jQuery 替换所有出现的 $.难点在于,变量通常定义为$a_variable_name,替换变量中的$会导致错误.

  1. It isn't always enough to just add jQuery.noConflict();. You may also need to replace all occurrences $ with jQuery. The difficulty is, variables are often defined as $a_variable_name, replacing the $ in variables will result in errors.

看看你是否能找到一个已经进行了noConflict编辑的tipsy版本.另请注意,通常需要在其他 jQuery 脚本中添加 noConflict 并将 $ 替换为 jQuery,尤其是当该脚本依赖于另一个脚本时.

See if you can find a version of tipsy with the noConflict edits already made. Note also, it is often necessary to add noConflict and replace $ with jQuery to other jQuery scripts especially if that script is dependant on another.

这确实解决了冲突,因为我已经这样做了一段时间.另请注意,如果您始终使用 jQuery,则通常不需要进行这些编辑.

This does solve conflicts as I have been doing this for some time. Note also, if you use jQuery throughout, these edits are not normally required.

加载脚本文件的顺序也很重要,请尝试重新排列它们.

The sequence you load script files is also important, try rearranging them.

仅在需要时执行脚本.换句话说,如果某段代码导致冲突,请使用脚本标签从需要它的页面而不是标题中加载它.

Only execute scripts when they are required. In other words, if a particular piece of code is causing conflict, load it from the page where it is required and not in the header, using script tags.

这篇关于如何解决这个 jQuery 插件冲突?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆