当我使用以下代码导入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>
答案 0 :(得分:1)
如果为两个版本定义'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>