web前端|js教程
异步加载,loadScript
web前端-js教程
A、语法:loadScript(url[,callback])
或者
loadScript(settings)
B、settings支持的参数:url:脚本路径
async:是否异步,默认false(HTML5)
charset:文件编码
cache:是否缓存,默认为true
success:加载成功后执行的函数,优先执行callback。
C、调用举例:
源码什么意思,vscode源,ubuntu背景图片,tomcat phph,sqlite编辑表,域名服务器是什么意思,wordpress 主页 插件,web前端 框架 下载,多进程爬虫python,php写商城,SEO优化源码,企业内部网站模板下载,html5网页制作汉化模板,js模板里面图片路径怎么写,查看页面源代码 查找,java 开源 项目管理系统,装修门户网站程序 cmslzw
//loadScript(url[,callback])
loadScript(“/jquery.js”);
loadScript(“/jquery.js”,function(){
console.log(1)
});
//loadScript(settings)
loadScript({“url”:”/jquery.js”,”async”:false,”charset”:”utf-8″,”cache”:false});
loadScript({“url”:”/jquery.js”,”async”:false,”charset”:”utf-8″,”success”:function(){
console.log(2)
}});
//或者你可以酱紫:
//loadScript(settings[,callback])
loadScript({“url”:”/jquery.js”,”async”:false,”charset”:”utf-8″},function(){
console.log($)
});
D、源代码:
58同城网源码,vscode的f5,ubuntu已杀死,tomcat8jsp,学爬虫视频,php伪静态分页,随州产品seo推广公司排名,知道一个网站怎么把源码下载,苹果cms主题模板下载地址lzw
function loadScript(url,callback) {
var head = document.head || document.getElementsByTagName(“head”)[0] || document.documentElement,
script,
options,
手机工具箱源码,vscode日志输出不显示,ubuntu蓝牙定位,tomcat记录日志文件,爬虫解析jhtml,php加载慢,江阴seo优化费用多少,开源免费网站建站程序,仿模板阁lzw
if (typeof url === “object”) {
options = url;
url = undefined;
}
s = options || {};
url = url || s.url;
callback = callback || s.success;
script = document.createElement(“script”);
script.async = s.async || false;
script.type = “text/javascript”;
if (s.charset) {
script.charset = s.charset;
}
if(s.cache === false){
url = url+( /\?/.test( url ) ? “&” : “?” )+ “_=” +(new Date()).getTime();
}
script.src = url;
head.insertBefore(script, head.firstChild);
if(callback){
document.addEventListener ? script.addEventListener(“load”, callback, false) : script.onreadystatechange = function() {
if (/loaded|complete/.test(script.readyState)) {
script.onreadystatechange = null
callback()
}
}
}
}