欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

动态加载js代码

程序员文章站 2022-08-05 20:24:27
动态加载js代码 function loadscirpt(src, fn, coding) { var script = document.createelement('scrip...

    动态加载js代码

    function loadscirpt(src, fn, coding) {
    	var script = document.createelement('script')
    	script.async = false
    	coding && script.charset = 'utf-8'
    	script.type = 'type/javascript'
    	script.readystate  script.onreadystatechange = function() {
    		('loaded' == script.readystate || 'complete' == script.readystate) && 
    			(script.onreadystatechange = null, fn && fn()) :
    		script.onload = function() {
    			fn && fn()
    		}
    	script.src = src 
    	document.body.appendchild(script)
    	}
    }