Jquery.noConflict issue?
I need two jQuery sources and i don't know if i am implementing .noConflict correctly?
<link href="count/jquery.countdown.css" rel="stylesheet" type="text开发者_如何学C/css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript" src="Count/jquery.countdown.js"></script>
<script type="text/javascript">
$(function () {
var Day = new Date();
Day = new Date(2015, 11, 22, 09, 00, 00, 00)
$('#defaultCountdown').countdown({until: Day});
$('#year').text(Day.getFullYear());
});
jQuery.noConflict(true);
</script>
<link rel="stylesheet" href="Video/css/jquery.fancybox.css" type="text/css" media="screen" />
<link rel="stylesheet" href="Video/css/style.css" type="text/css" media="screen" />
<script type="text/javascript" src="Video/js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="Video/js/flowplayer-3.1.1.min.js"></script>
<script type="text/javascript" src="Video/js/jquery.fancybox-1.2.1.pack.js"></script>
<script type="text/javascript" src="Video/js/jquery.easing.1.3.js"></script>
<script type="text/javascript" src="Video/js/fancyplayer.js"></script>
<script type="text/javascript">
var videopath = "http://www.site.co.uk/Video/";
var swfplayer = videopath + "videos/flowplayer-3.1.1.swf";
</script>
Update: Regarding your update, I think you just need to specify a parameter for your ready handler:
$(function($) {
//...
});
jQuery.noConflict(true);
So that the code inside the handler refers to the first version and not to the second one (the second jQuery include will overwrite $
otherwise).
I think if you pass true
, which essentially also resets jQuery
, you have to assign a reference to that jQuery version on your own:
var jQueryVersionX = jQuery.noConflict(true);
jQueryVersionX(function($) {
// $ references the jQueryVersionX;
});
jQuery passes a reference to itself as first argument to the ready handler.
If you include both scripts in the header, then jQuery
will first reference the second included version. After calling jQuery.noConflict(true)
, jQuery
will refer to the first included version.
But note from the documentation:
If necessary, we can free up the
jQuery
name as well by passingtrue
as an argument to the method. This is rarely necessary, and if we must do this (for example, if we need to use multiple versions of the jQuery library on the same page), we need to consider that most plug-ins rely on the presence of the jQuery variable and may not operate correctly in this situation.
Make sure you include the versions and the plugins in the right order.
精彩评论