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)
})