javascript - 如何使用多个版本的 jQuery?
问题描述
Stack Overflow 上还有其他答案,但是我无法让它们中的任何一个起作用。
我需要使用 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 中检查了页面并没有显示任何错误,但它根本不会运行滑块。
解决方案
这是一次加载(和使用)两个版本的 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
});
});
推荐阅读
- javascript - 如果将 html 表上的 Javascript 过滤器注入到 div 中,它将不起作用。如果表格加载了页面,它可以工作
- python - 如何将默认文件设置为在 Visual Studio 代码中运行的第一个文件?
- sql-server - 为什么不阻塞行?
- python - Python 到 csv 文件
- c# - Microsoft 同步框架在配置时增加了数据库大小
- javascript - 工作函数如何返回另一个接受另一个参数的函数?
- c# - 如何将我的表(数据库)的列名显示到组合框中
- database - 在 MongoDB 中,如何检索字段 X 大于字段 Y 的值 N 的一组结果?
- android - 从 RecyclerView 适配器获取 EditText 值
- swift - URLSessionConfiguration 背景,超时问题,在 Postman 中工作正常