判断jquery是否已经加载,如果没有动态加载
方法一:
// Only do anything if jQuery isn't defined
if (typeof jQuery == 'undefined') { if (typeof $ == 'function') {
// warning, global var
thisPageUsingOtherJSLibrary = true;
} function getScript(url, success) { var script = document.createElement('script');
script.src = url; var head = document.getElementsByTagName('head')[0],
done = false; // Attach handlers for all browsers
script.onload = script.onreadystatechange = function() { if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) { done = true; // callback function provided as param
success(); script.onload = script.onreadystatechange = null;
head.removeChild(script); }; }; head.appendChild(script); }; getScript('http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js', function() { if (typeof jQuery=='undefined') { // Super failsafe - still somehow failed... } else { // jQuery loaded! Make sure to use .noConflict just in case
fancyCode(); if (thisPageUsingOtherJSLibrary) { // Run your jQuery Code } else { // Use .noConflict(), then run your jQuery Code } } }); } else { // jQuery was already loaded // Run your jQuery Code }; //该代码片段来自于: http://www.sharejs.com/codes/javascript/4281
方法二:document.write
var jQueryScriptOutputted = false;
function initJQuery() { //if the jQuery object isn't available
if (typeof(jQuery) == 'undefined') { if (! jQueryScriptOutputted) {
//only output the script once..
jQueryScriptOutputted = true; //output the script (load it from google api)
document.write("<scr" + "ipt type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></scr" + "ipt>");
}
setTimeout("initJQuery()", 50);
} else { $(function() {
// do anything that needs to be done on document.ready
// don't really need this dom ready thing if used in footer
});
} }
initJQuery();
//该代码片段来自于: http://www.sharejs.com/codes/javascript/4281
判断jquery是否已经加载,如果没有动态加载的更多相关文章
- 利用Jquery的load函数实现页面的动态加载
利用Jquery的load函数实现页面的动态加载 js的强大功能相信大家都知晓,今天通过jquery的库函数load可以更加方便的实现页面的动态刷新,经过几天的研究与探索,终于有所成效!吾心甚蔚! ...
- Delphi静态加载DLL和动态加载DLL示例
下面以Delphi调用触摸屏动态库xtkutility.dll为例子,说明如何静态加载DLL和动态加载DLL. 直接上代码. 1.静态加载示例 unit Unit1; interface uses W ...
- vc静态加载dll和动态加载dll
如果你有a.dll和a.lib,两个文件都有的话可以用静态加载的方式: message函数的声明你应该知道吧,把它的声明和下面的语句写到一个头文件中 #pragma comment(lib, &quo ...
- Vue加载组件、动态加载组件的几种方式
https://cn.vuejs.org/v2/guide/components.html https://cn.vuejs.org/v2/guide/components-dynamic-async ...
- c# 创建Excel com加载项Ribbon动态加载工作簿和工作表
使用 VSTO 创建外接程序,Gallery控件动态加载工作簿名称 代码如下: 加载工作簿名称: private void Gallery1_ItemsLoading(object sender, R ...
- android左右滑动加载分页以及动态加载数据
android UI 往右滑动,滑动到最后一页就自动加载数据并显示 如图: package cn.anycall.ju; import java.util.ArrayList; import java ...
- 雷林鹏分享:jQuery EasyUI 树形菜单 - 树形网格动态加载
jQuery EasyUI 树形菜单 - 树形网格动态加载 动态加载树形网格有助于从服务器上加载部分的行数据,避免加载大型数据的长时间等待.本教程将向您展示如何创建带有动态加载特性的树形网格(Tree ...
- 第一百一十八节,JavaScript,动态加载脚本和样式
JavaScript,动态加载脚本和样式 一动态脚本 当网站需求变大,脚本的需求也逐步变大.我们就不得不引入太多的JS脚本而降低了整站的性能,所以就出现了动态脚本的概念,在适时的时候加载相应的脚本. ...
- 动态加载js css 插件
简介 动态加载js,css在现在以及将来肯定是很重要的.目前来看前端代码编写的业务量已经远远超过后端编写的.随着对用户体验度逐渐增强,前端业务复杂,加载速度变得很慢很慢.为了解决这个问题,目前出现的两 ...
- 通过Activity动态加载Fragment创建主界面构架
在做项目中,需要建立一个主界面框架,尝试过使用ViewPager ,后来又换成了使用Activity动态加载Fragment实现选项卡的效果.总结一下方便以后回顾. 先给出总体效果: 要实现上述效果, ...
随机推荐
- 启动httpd服务:SSLCertificateFile: file '/var/www/miq/vmdb/certs/server.cer' does not exist or is empty
启动httpd服务,失败: [root@test vmdb]# service httpd restart Stopping httpd: [FAILED] Starting httpd: Synta ...
- CentOS修改163源(转载)
From:http://www.linuxidc.com/Linux/2012-08/69043.htm #CentOS-Base.repo其他版本文件在http://mirrors.163.com/ ...
- Undefined symbols for architecture i386:"_OBJC_CLASS_$_xx", referenced from: 解决方法
多个人共同操作同一个项目或拷贝项目时,经常会出现类似这样的问题: Undefined symbols for architecture i386: "_OBJC_CLASS_$_xx文件名& ...
- 异步任务神器 Celery 简明笔记
转自:http://www.jianshu.com/p/1840035cb510 异步任务 异步任务是web开发中一个很常见的方法.对于一些耗时耗资源的操作,往往从主应用中隔离,通过异步的方式执行.简 ...
- esriSRProjCS4Type Constants
ArcGIS Developer Help (Geometry) esriSRProjCS4Type Constants See Also esriSRProjCSType Constants ...
- [SQL]sql语句如何修改字段长度
语法: alter table <表名> alter column <字段名> 新类型名(长度) 示例: 假如有名T1,字段名F1,原来F1为varchar(),现在要改为va ...
- @InitBinder
类型转换: 请求url: http://localhost:8080/SSHDemo2/stu/pro?s=zk,19 传入参数 s=zk,19 转换为Student public class ...
- IntelliJ IDEA显示行号方法
File->Settings->Editor->General->Appearence->Show line numbers
- Codeforces Round #218 (Div. 2) D. Vessels
D. Vessels time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...
- VS2010 和VS2012 的程序在XP上运行的方法
问题表象: VS2012编译的程序不能再XP下运行 解决办法: 1.工程设置的方法 在vs2012里,右键 属性->配置属性-常规->平台工具集->选个VS2008什么的就ok了~ ...