如何动态加载外部CSS与JS文件(2)
来源:互联网 责任编辑:栏目编辑 发表时间:2013-07-01 05:15 点击:次
By referencing the HEAD element of the page first and then calling appendChild(), this means the newly created element is added to the very end of the HEAD tag. Furthermore, you should be aware that no existing element is harmed in the adding of the new element- that is to say, if you call loadjscssfile("myscript.js", "js") twice, you now end up with two new "script" elements both pointing to the same Javascript file. This is problematic only from an efficiency standpoint, as you'll be adding redundant elements to the page and using unnecessary browser memory in the process. A simple way to prevent the same file from being added more than once is to keep track of the files added by loadjscssfile(), and only load a file if it's new:
var filesadded="" //保存已经绑定文件名字的数组变量 function che 相关新闻>>最新推荐更多>>>
|