動(dòng)態(tài)加載jQuery的兩種方法實(shí)例分析
本文實(shí)例講述了動(dòng)態(tài)加載jQuery的兩種方法。分享給大家供大家參考。具體如下:
第一種方法參考本站之前有人發(fā)的代碼,增加了加載檢測(cè);
第二種方法來自去年的12306刷票腳本。
第一種方法:
function withjQuery(callback) { if(!(window.jQuery)) { var js = document.createElement('script'); js.setAttribute('src', 'https://dynamic.12306.cn/otsweb/js/common/jquery-1.4.2.min.js?version=5.47'); js.setAttribute('type', 'text/javascript'); js.onload = js.onreadystatechange = function() { if (!this.readyState || this.readyState === 'loaded' || this.readyState === 'complete') { if(callback && typeof callback === "function") { callback(); } js.onload = js.onreadystatechange = null; } }; document.getElementsByTagName('head')[0].appendChild(js); } } withjQuery( function() { $(function(){ alert("jQuery loaded"); })(); } );
第二種方法:
// ==UserScript== // @name 12306 Booking Assistant // @version 1.4.0 // @author zzdhidden@gmail.com // @namespace https://github.com/zzdhidden // @description 12306 訂票助手之(自動(dòng)登錄,自動(dòng)查票,自動(dòng)訂單) // @include *://dynamic.12306.cn/otsweb/* // @require https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js // ==/UserScript== function withjQuery(callback, safe){ if(typeof(jQuery) == "undefined") { var script = document.createElement("script"); script.type = "text/javascript"; script.src = "https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"; if(safe) { var cb = document.createElement("script"); cb.type = "text/javascript"; cb.textContent = "jQuery.noConflict();(" + callback.toString() + ")(jQuery, window);"; script.addEventListener('load', function() { document.head.appendChild(cb); }); } else { var dollar = undefined; if(typeof($) != "undefined") dollar = $; script.addEventListener('load', function() { jQuery.noConflict(); $ = dollar; callback(jQuery, window); }); } document.head.appendChild(script); } else { setTimeout(function() { //Firefox supports callback(jQuery, typeof unsafeWindow === "undefined" ? window : unsafeWindow); }, 30); } } withjQuery(function($, window){ $(function() { alert("jQuery loaded"); })(); }, true);
希望本文所述對(duì)大家的jquery程序設(shè)計(jì)有所幫助。
- 動(dòng)態(tài)加載jQuery的方法
- jQuery結(jié)合ajax實(shí)現(xiàn)動(dòng)態(tài)加載文本內(nèi)容
- jQuery實(shí)現(xiàn)頁面滾動(dòng)時(shí)動(dòng)態(tài)加載內(nèi)容的方法
- 使用jquery動(dòng)態(tài)加載js文件的方法
- 一個(gè)簡(jiǎn)單的動(dòng)態(tài)加載js和css的jquery代碼
- 三種動(dòng)態(tài)加載js的jquery實(shí)例代碼另附去除js方法
- 動(dòng)態(tài)加載jquery庫的方法
- jquery Tab效果和動(dòng)態(tài)加載的簡(jiǎn)單實(shí)例
- jquery動(dòng)態(tài)加載select下拉框示例代碼
相關(guān)文章
jQuery+CSS實(shí)現(xiàn)一個(gè)側(cè)滑導(dǎo)航菜單代碼
側(cè)滑菜單在網(wǎng)站設(shè)計(jì)中應(yīng)用比較廣泛,在許多網(wǎng)站上都可以看到此種類型的菜單。本文給大家介紹jQuery+CSS實(shí)現(xiàn)一個(gè)側(cè)滑導(dǎo)航菜單代碼,需要的朋友參考下吧2016-05-05Jquery通過Ajax訪問XML數(shù)據(jù)的小例子
這篇文章主要介紹了Jquery通過Ajax訪問XML數(shù)據(jù),有需要的朋友可以參考一下2013-11-11基于jQuery Easyui實(shí)現(xiàn)登陸框界面
本文通過實(shí)例代碼給大家分享了基于jQuery Easyui實(shí)現(xiàn)登陸框界面,代碼簡(jiǎn)單易懂,非常不錯(cuò),具有參考借鑒價(jià)值,需要的的朋友參考下吧2017-07-07jquery 實(shí)現(xiàn)滾動(dòng)條下拉時(shí)無限加載的簡(jiǎn)單實(shí)例
下面小編就為大家?guī)硪黄猨query 實(shí)現(xiàn)滾動(dòng)條下拉時(shí)無限加載的簡(jiǎn)單實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-06-06jQuery實(shí)現(xiàn)的淡入淡出圖片輪播效果示例
這篇文章主要介紹了jQuery實(shí)現(xiàn)的淡入淡出圖片輪播效果,涉及jQuery基于定時(shí)器的頁面元素動(dòng)態(tài)操作相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2018-08-08jquery獲取table指定行和列的數(shù)據(jù)方法(當(dāng)前選中行、列)
下面小編就為大家?guī)硪黄猨query獲取table指定行和列的數(shù)據(jù)方法(當(dāng)前選中行、列)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-11-11基于jquery實(shí)現(xiàn)狀態(tài)限定編輯的代碼
基于jquery實(shí)現(xiàn)狀態(tài)限定編輯的代碼,需要的朋友可以參考下2012-02-02