使用js代码加载js文件

325次阅读
没有评论
function loadScript(src, attrs) {return new Promise((resolve, reject) => {
        try {let scriptEle = document.createElement('script')
                scriptEle.type = 'text/javascript'
                scriptEle.src = src
                for (let key in attrs) {scriptEle.setAttribute(key, attrs[key])
                }
                scriptEle.addEventListener('load', function () {resolve('成功')
                })
                document.body.appendChild(scriptEle)
            } catch (err) {reject(err)
            }
    })
    }

loadScript('https://cdn.bootcdn.net/ajax/libs/layer/3.5.1/layer.js', {async: true}).then(res => {console.log(res)
        })
正文完
有偿技术支持加微信
post-qrcode
 0
评论(没有评论)
验证码