同时使用2个不同版本的Jquery [英] Using 2 different versions of Jquery at the same time
本文介绍了同时使用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="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
$jquery_2_1 = jQuery.noConflict();
</script>
<script src="https://ajax.googleapis.com/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="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
$jquery_2_1 = jQuery.noConflict();
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<script type="text/javascript">
$jquery_1_12 = jQuery.noConflict();
</script>
这篇关于同时使用2个不同版本的Jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文