同时使用2个不同版本的Jquery

编程入门 行业动态 更新时间:2024-10-24 20:19:17
本文介绍了同时使用2个不同版本的Jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当我使用以下代码导入2个版本的jQuery时,jquery.1.12.4有效,但jquery.2.1.3不起作用.

<script type='text/javascript' src='js/jquery.2.1.3.js'></script> <script type="text/javascript"> $213 = jQuery.noConflict(); </script> <script type='text/javascript' src='js/jquery.1.12.4.js'></script>

jquery.1.12.4的功能有效,但jquery.2.1.3中的以下功能无效:

<script> $213(function() { var Accordion = function(el, multiple) { this.el = el || {}; this.multiple = multiple || false; // Variables privadas var links = this.el.find('.link'); // Evento links.on('click', {el: this.el, multiple: this.multiple}, this.dropdown) } Accordion.prototype.dropdown = function(e) { var $el = e.data.el; $this = $(this), $next = $this.next(); $next.slideToggle(); $this.parent().toggleClass('open'); if (!e.data.multiple) { $el.find('.submenu').not($next).slideUp().parent().removeClass('open'); }; } var accordion = new Accordion($('#accordion'), false); }); </script>

解决方案

如果为两个版本定义'noConflict(),您是否可以尝试以下方式工作?

jQuery(document).ready(function() { $jquery_2_1(function(jQuery) { var Accordion = function(el, multiple) { this.el = el || {}; this.multiple = multiple || false; // Variables privadas var links = this.el.find('.link'); // Evento links.on('click', { el: this.el, multiple: this.multiple }, this.dropdown) } Accordion.prototype.dropdown = function(e) { var $el = e.data.el; $this = $(this), $next = $this.next(); $next.slideToggle(); $this.parent().toggleClass('open'); if (!e.data.multiple) { $el.find('.submenu').not($next).slideUp().parent().removeClass('open'); }; } var accordion = new Accordion(jQuery('#accordion'), false); }); });

<script src="ajax.googleapis/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script type="text/javascript"> $jquery_2_1 = jQuery.noConflict(); </script> <script src="ajax.googleapis/ajax/libs/jquery/1.2.6/jquery.min.js"></script> <script type="text/javascript"> $jquery_1_12 = jQuery.noConflict(); </script>

When I use the following code to import 2 versions of jQuery, jquery.1.12.4 works but jquery.2.1.3 doesn't work.

<script type='text/javascript' src='js/jquery.2.1.3.js'></script> <script type="text/javascript"> $213 = jQuery.noConflict(); </script> <script type='text/javascript' src='js/jquery.1.12.4.js'></script>

the function of jquery.1.12.4 works but the following function from jquery.2.1.3 does not work:

<script> $213(function() { var Accordion = function(el, multiple) { this.el = el || {}; this.multiple = multiple || false; // Variables privadas var links = this.el.find('.link'); // Evento links.on('click', {el: this.el, multiple: this.multiple}, this.dropdown) } Accordion.prototype.dropdown = function(e) { var $el = e.data.el; $this = $(this), $next = $this.next(); $next.slideToggle(); $this.parent().toggleClass('open'); if (!e.data.multiple) { $el.find('.submenu').not($next).slideUp().parent().removeClass('open'); }; } var accordion = new Accordion($('#accordion'), false); }); </script>

解决方案

can you try the following way it should work if you define 'noConflict() for both versions

jQuery(document).ready(function() { $jquery_2_1(function(jQuery) { var Accordion = function(el, multiple) { this.el = el || {}; this.multiple = multiple || false; // Variables privadas var links = this.el.find('.link'); // Evento links.on('click', { el: this.el, multiple: this.multiple }, this.dropdown) } Accordion.prototype.dropdown = function(e) { var $el = e.data.el; $this = $(this), $next = $this.next(); $next.slideToggle(); $this.parent().toggleClass('open'); if (!e.data.multiple) { $el.find('.submenu').not($next).slideUp().parent().removeClass('open'); }; } var accordion = new Accordion(jQuery('#accordion'), false); }); });

<script src="ajax.googleapis/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script type="text/javascript"> $jquery_2_1 = jQuery.noConflict(); </script> <script src="ajax.googleapis/ajax/libs/jquery/1.2.6/jquery.min.js"></script> <script type="text/javascript"> $jquery_1_12 = jQuery.noConflict(); </script>

更多推荐

同时使用2个不同版本的Jquery

本文发布于:2023-11-06 22:47:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1564880.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:版本   Jquery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!