动态加载JS脚本

2019-06-13  本文已影响0人  404发现号

头脑笨不可怕,但是我认真啊,但是我刻苦啊,但是我爱学啊😄。


<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <meta http-equiv="X-UA-Compatible" content="ie=edge">

    <script src="https://ajax.googlepis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>

    <script>

        if(!window.jQuery) document.write('<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"><\/script>');

    </script>

    <title>Document</title>

</head>

<body>

    <script>

        console.log(window.jQuery)   

    </script>

</body>

</html>

总结:当CDN文件丢失或者加载失败的时候 使用判断的方式动态加载外链脚本或将脚本下载到本地即可

上一篇 下一篇

猜你喜欢

热点阅读