onload触发callback的方法实现(兼容主流浏览器)

https://blog.csdn.net/iteye_2341/article/details/82618209

loadFile(url, callback) {
	  vars = document.createElement('script')
	  s.type = 'text/javascript'
	  s.src = url
	  // 加载完之后触发回调,有回调 就触发
	  if (callback) s.onload  = callback;
	  document.body.appendChild(s)
	}

调用:


this.loadFile('url', function() { }    });

你可能感兴趣的:(onload触发callback的方法实现(兼容主流浏览器))