JS - 动态引入js文件
发布日期:2021-10-02 12:55:41 浏览次数:22 分类:技术文章

本文共 693 字,大约阅读时间需要 2 分钟。

js动态向 head 标签中引入js文件

function dynamicLoadJs(url, callback) {
var head = document.getElementsByTagName('head')[0]; var script = document.createElement('script'); script.type = 'text/javascript'; script.src = url; if (typeof (callback) == 'function') {
script.onload = script.onreadystatechange = function () {
if (!this.readyState || this.readyState === "loaded" || this.readyState === "complete") {
callback(); script.onload = script.onreadystatechange = null; } }; } head.appendChild(script);}//引入的js文件地址let url='https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js'dynamicLoadJs(url);

转载地址:https://blog.csdn.net/Jie_1997/article/details/112011603 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:JS - 获取数据类型
下一篇:JS - 判断当前浏览器是不是PC浏览器

发表评论

最新留言

关注你微信了!
[***.104.42.241]2024年04月09日 22时42分43秒