示例如下:通过document.createElement,动态将js文件引入
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title>
</head><body><div><button onclick="submit()">click</button></div>
</body>
<script>function submit() {var link = document.createElement('link');link.rel = "stylesheet";link.href = "https://cdn.jsdmirror.com/gh/MCCRNFC-SNLoong/LayuiCdn/layui-v2.7.6/css/layui.css";document.head.appendChild(link);var script = document.createElement('script');script.type = 'text/javascript';script.src = 'https://cdn.jsdmirror.com/gh/MCCRNFC-SNLoong/LayuiCdn/layui-v2.7.6/layui.js';script.onload = function () {console.log('脚本加载完成');var html = `<div><div class="layui-form-item"><div class="layui-inline"><label class="layui-form-label">充值账号</label><div class="layui-input-inline"><input type="tel" name="text" required autocomplete="off" class="layui-input" value="zhangsan" disabled style="color:green" ></div></div></div><div class="layui-form-item"><div class="layui-inline"><label class="layui-form-label">充值金额</label><div class="layui-input-inline" style="width: 100px;"><input type="text" name="price_min" placeholder="¥" autocomplete="off" required class="layui-input" value ="100" disabled style="color:red"></div></div></div><div class="layui-form-item"><label class="layui-form-label">充值平台</label><div class="layui-input-block"><select name="interest" lay-filter="aihao"><option value="0">微信</option><option value="1" selected="">支付宝</option></select></div></div><div class="layui-form-item"><div class="layui-input-block"><button type="submit" class="layui-btn" lay-submit="" onclick="return layer.load(2, {time: 3*1000});" >立即提交</button></div></div></div>`;layer.open({type: 1,title: '充值',content: html});};document.head.appendChild(script);}
</script></html>