Two different versions of jQuery on the same HTML page

I have an HTML document in which I mentioned jQuery version 1.2.2 in the header for the thick box, and I later referenced jQuery 1.7.1 immediately before the tag </body>, which is intended for image slide shows.

The problem is that the thick box will not work if the link to jQuery 1.7.1 is not removed and then stops the slide show.

I have googled around to find out about the conflict $, but none of the suggested solutions worked.

The most common I've seen and tried: var $j = jQuery.noConflict();

How can i solve this?

+5
source share
5 answers

If the plugins behave well, then this should work:

<script src="jquery-1.2.2.js"></script>
<script src="thickbox.js"></script>
<script src="jquery-1.7.1.js"></script>
<script src="slideshow.js"></script>

(, script .) () ( jQuery 1.4.2 jQuery 1.7.1, Google 1.2.2).

, $, jQuery global , , , :

// Example plug-in setup
(function($) {
    // ...Plug-in code using `$` here -- note it a *local* `$`,
    // not the global `$`, and not the global `jQuery`...
})(jQuery);

(function() {
    var $ = jQuery;

    // ...Plug-in code using `$` here -- note it a *local* `$`,
    // not the global `$`, and not the global `jQuery`...
})();

jQuery , .

, :

jQuery(function($) {
    // ...Plug-in code using `$` here -- note it a *local* `$`,
    // not the global `$`, and not the global `jQuery`...
});

... jQuery, .

( , jQuery 1.2.2 - jQuery 1.7.1) script.

"" "". , , .


, , jQuery 1.2.2 , , ( ), , jQuery, .

+2
<script src="http://code.jquery.com/jquery-1.2.2.min.js"></script>
<script type="text/javascript">
  var jQ122 = jQuery.noConflict();
</script>
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
  var jQ171 = jQuery.noConflict();


  (function($) { 
    $(function() {
      // here $ is jQuery 1.2.2
    });
  })(jQ122);


  (function($) { 
    $(function() {
      // here $ is jQuery 1.7.1
    });
  })(jQ171);
</script>
+2

jQuery. , jQuery.

0

, ( ), ...

... :

<script src="jquery-1.4.js"></script>
var jQuery14 = jQuery;
<script src="jquery-1.7.js"></script>
var jQuery17 = jQuery;

, jQuery , :

(function( $ ){
     // all your plugins code would be here
})( jQuery );     // replace "jQuery" with one of your respective jQuery14/jQuery17 versions/variables

.. , ! !:)

0

jQuery.noConflict(); jQuery .

IE8 , .

, iframe .

jQuery , .

:

<iframe frameborder="0" width="700" height ="400" scrolling="no" seamless="seamless" src="your.html"></iframe>
0

All Articles