日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

jQuery常用的全局方法源码

發布時間:2025/3/8 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 jQuery常用的全局方法源码 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

下面常用方法的詳細使用請查看:http://www.cnblogs.com/moqiutao/p/4775725.html

1.$.noConflict()方法

語法:jQuery.noConflict(removeAll)

removeAll:布爾值。指示是否允許徹底將 jQuery 變量還原。

源碼:

var// Map over jQuery in case of overwrite_jQuery = window.jQuery,// Map over the $ in case of overwrite_$ = window.$;jQuery.noConflict = function( deep ) {if ( window.$ === jQuery ) {window.$ = _$;}if ( deep && window.jQuery === jQuery ) {window.jQuery = _jQuery;}return jQuery; };

?2.$.proxy()方法

// A global GUID counter for objectsguid: 1,// Bind a function to a context, optionally partially applying any// arguments.proxy: function( fn, context ) {var tmp, args, proxy;if ( typeof context === "string" ) {tmp = fn[ context ];context = fn;fn = tmp;}// Quick check to determine if target is callable, in the spec// this throws a TypeError, but we will just return undefined.if ( !jQuery.isFunction( fn ) ) {return undefined;}// Simulated bindargs = slice.call( arguments, 2 );proxy = function() {return fn.apply( context || this, args.concat( slice.call( arguments ) ) );};// Set the guid of unique handler to the same of original handler, so it can be removedproxy.guid = fn.guid = fn.guid || jQuery.guid++;return proxy;}

?3.jQuery.extend = jQuery.fn.extend

// 合并兩個或更多對象的屬性到第一個對象中,jQuery后續的大部分功能都通過該函數擴展// 通過jQuery.fn.extend擴展的函數,大部分都會調用通過jQuery.extend擴展的同名函數// 如果傳入兩個或多個對象,所有對象的屬性會被添加到第一個對象target// 如果只傳入一個對象,則將對象的屬性添加到jQuery對象中。// 用這種方式,我們可以為jQuery命名空間增加新的方法。可以用于編寫jQuery插件。// 如果不想改變傳入的對象,可以傳入一個空對象:$.extend({}, object1, object2);// 默認合并操作是不迭代的,即便target的某個屬性是對象或屬性,也會被完全覆蓋而不是合并// 第一個參數是true,則會迭代合并// 從object原型繼承的屬性會被拷貝// undefined值不會被拷貝// 因為性能原因,JavaScript自帶類型的屬性不會合并// jQuery.extend( target, [ object1 ], [ objectN ] )// jQuery.extend( [ deep ], target, object1, [ objectN ] ) jQuery.extend = jQuery.fn.extend = function() {var options, name, src, copy, copyIsArray, clone,target = arguments[0] || {},i = 1,length = arguments.length,deep = false;// Handle a deep copy situation// 如果第一個參數是boolean型,可能是深度拷貝if ( typeof target === "boolean" ) {deep = target;target = arguments[1] || {};// skip the boolean and the target// 跳過boolean和target,從第3個開始 i = 2;}// Handle case when target is a string or something (possible in deep copy)// target不是對象也不是函數,則強制設置為空對象if ( typeof target !== "object" && !jQuery.isFunction(target) ) {target = {};}// extend jQuery itself if only one argument is passed// 如果只傳入一個參數,則認為是對jQuery擴展if ( length === i ) {target = this;--i;}for ( ; i < length; i++ ) {// Only deal with non-null/undefined values// 只處理非空參數if ( (options = arguments[ i ]) != null ) {// Extend the base objectfor ( name in options ) {src = target[ name ];copy = options[ name ];// Prevent never-ending loop// 避免循環引用if ( target === copy ) {continue;}// Recurse if we're merging plain objects or arrays// 深度拷貝且值是純對象或數組,則遞歸if ( deep && copy && ( jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)) ) ) {// 如果copy是數組if ( copyIsArray ) {copyIsArray = false;// clone為src的修正值 clone = src && jQuery.isArray(src) ? src : [];// 如果copy的是對象 } else {// clone為src的修正值 clone = src && jQuery.isPlainObject(src) ? src : {};}// Never move original objects, clone them// 遞歸調用jQuery.extend target[ name ] = jQuery.extend( deep, clone, copy );// Don't bring in undefined values// 不能拷貝空值 } else if ( copy !== undefined ) {target[ name ] = copy;}}}}// Return the modified object// 返回更改后的對象return target;};

?

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的jQuery常用的全局方法源码的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。