项目需求
需求是完成一个插入页面webim插件,希望只在页面中引用一条webim.js,即可以将整个webim插入页面,那么我们就需要在引入的这一条webim.js文件内执行一些方法,来讲我们整个插件都引入进来
window.onload = function () {
let body = document.body
let box = document.createElement('div')
let head = document.getElementsByTagName('head')[0];
/*引入layui.js*/
let script = document.createElement('script');
script.type = 'text/javascript';
script.src = './layui/layui.js';
head.appendChild(script);
script.onload = function(){
layui.use('layer', function(){
window.layer = layui.layer;
});
}
}
这是通过webim.js引入layui的方法,通过window.onload触发的事件,我们直接找到页面的head部分,然后创建一个script标签,之后为该标签附上type、src等属性,之后将其append到页面的head部分。
使用script.onload方法&#