关于堆栈溢出还有其他答案,但是我无法让它们起作用。
我需要使用2个版本的jQuery。这是我的代码:
我链接到第一个版本,然后输入以下代码:
<script>
var $i = jQuery.noConflict();
</script>
然后我链接到第二版本并获得以下代码:
<script>
var $j = jQuery.noConflict();
</script>
这是我需要在第二个版本$ j中运行的代码
<script type="text/javascript">
$j.ready(function() {
$j('#slider').layerSlider({
sliderVersion: '6.2.1',
type: 'fullsize',
responsiveUnder: 0,
fullSizeMode: 'hero',
maxRatio: 1,
parallaxScrollReverse: true,
hideUnder: 0,
hideOver: 100000,
skin: 'outline',
showBarTimer: true,
showCircleTimer: false,
thumbnailNavigation: 'disabled',
allowRestartOnResize: true,
skinsPath: 'skins/',
height: 800
});
});
</script>
我在Chrome中检查了该页面,但没有显示任何错误,但根本无法运行滑块。
答案 0 :(得分:1)
这是一次加载(和使用)两个版本的jQuery的一种方法。完全不需要致电.noConflict
。
console.log(jQuery3.fn.jquery);
console.log(jQuery2.fn.jquery);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>var jQuery3 = jQuery;</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script>var jQuery2 = jQuery;</script>
然后使用jQuery2
运行滑块脚本:
$jQuery2.ready(function() {
$jQuery2('#slider').layerSlider({
sliderVersion: '6.2.1',
type: 'fullsize',
responsiveUnder: 0,
fullSizeMode: 'hero',
maxRatio: 1,
parallaxScrollReverse: true,
hideUnder: 0,
hideOver: 100000,
skin: 'outline',
showBarTimer: true,
showCircleTimer: false,
thumbnailNavigation: 'disabled',
allowRestartOnResize: true,
skinsPath: 'skins/',
height: 800
});
});