建站资源下载详情
为您免费提供多种建站资源下载,包括网站模板下载、前端插件下载和字体下载!您只需注册为会员即可任意下载!

JQuery迁移辅助插件Migrate

来源:易助科技网浏览量:11收藏

简介


jquery migrate是一个应用迁移辅助插件,是用于高级版本兼容低级版本的辅助插件;该插件能够解决jquery升级后新旧代码不兼容的问题,简单来说就是把不支持的函数再写出来支持一下。例如jQuery版本用的是1.x,计划升级到3.x,就可以在页面删除1.x版本,换成3.x版本,如果有脚本错误,就引入jquery-migrate插件用于兼容低版本,同时也显示低版本方法替换成新版本方法的方案。



使用


1.  用法示例


<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>test</title>
  <script type="text/javascript" src="jquery-1.6.1.js"></script>
  <script type="text/javascript">
    $(document).ready(function(){
      $("button").click(function(){
        alert($("li").size());
      });
    });
  </script>
</head>
<body>
  <button>测试按钮</button>
  <ul>
    <li>Coffee</li>
    <li>Milk</li>
    <li>Soda</li>
  </ul>
</body>
</html>


把<script type="text/javascript" src="jquery-1.6.1.js"></script>替换成<script type="text/javascript" src="jquery-3.3.1.js"></script>这时点击按钮,在Chrome浏览器开发者窗口中显示脚本错误:

$(...).size is not a function


在页面再引入<script src="jquery-migrate-3.0.1.js"></script>点击按钮,正常弹出“3”。同时提示size方法被弃用使用length代替:


jQuery.fn.size() is deprecated and removed; use the .length property  



相关链接


GitHub 地址 :  https://github.com/jquery/jquery-migrate

npm 地址 :  https://www.npmjs.com/package/jquery-migrate