js代码 向网页添加jquery库

<script>
  !function () {
    function c () {
      var dom = document.getElementById('loadJs');
      var createDom = document.createElement('script');
      dom && document.getElementsByTagName("head")[0].removeChild(dom);
      createDom.id = 'loadJs';
      createDom.type = 'text/javascript';
      createDom.onerror = function () {return b == a.length - 1 ? (alert("加载失败"), void 0) : (b++, c(), void 0)
      }
      createDom.src = a[b];
      document.getElementsByTagName('head')[0].appendChild(createDom);
    }
    var a = [`https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js?_=${new Date().getTime()}`];
    var b = 0;
    c();
  }();
</script>

 

posted @ 2020-11-05 16:07  Mablevi  阅读(266)  评论(0编辑  收藏  举报