⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jquery.js

📁 jQuery即学即用
💻 JS
📖 第 1 页 / 共 5 页
字号:
		// Compute a unique ID for the element		if ( !id ) { 			id = ++uuid;		}		// Avoid generating a new cache unless none exists and we		// want to manipulate it.		if ( typeof name === "object" ) {			elem[ expando ] = id;			thisCache = cache[ id ] = jQuery.extend(true, {}, name);		} else if ( !cache[ id ] ) {			elem[ expando ] = id;			cache[ id ] = {};		}		thisCache = cache[ id ];		// Prevent overriding the named cache with undefined values		if ( data !== undefined ) {			thisCache[ name ] = data;		}		return typeof name === "string" ? thisCache[ name ] : thisCache;	},	removeData: function( elem, name ) {		if ( elem.nodeName && jQuery.noData[elem.nodeName.toLowerCase()] ) {			return;		}		elem = elem == window ?			windowData :			elem;		var id = elem[ expando ], cache = jQuery.cache, thisCache = cache[ id ];		// If we want to remove a specific section of the element's data		if ( name ) {			if ( thisCache ) {				// Remove the section of cache data				delete thisCache[ name ];				// If we've removed all the data, remove the element's cache				if ( jQuery.isEmptyObject(thisCache) ) {					jQuery.removeData( elem );				}			}		// Otherwise, we want to remove all of the element's data		} else {			if ( jQuery.support.deleteExpando ) {				delete elem[ jQuery.expando ];			} else if ( elem.removeAttribute ) {				elem.removeAttribute( jQuery.expando );			}			// Completely remove the data cache			delete cache[ id ];		}	}});jQuery.fn.extend({	data: function( key, value ) {		if ( typeof key === "undefined" && this.length ) {			return jQuery.data( this[0] );		} else if ( typeof key === "object" ) {			return this.each(function() {				jQuery.data( this, key );			});		}		var parts = key.split(".");		parts[1] = parts[1] ? "." + parts[1] : "";		if ( value === undefined ) {			var data = this.triggerHandler("getData" + parts[1] + "!", [parts[0]]);			if ( data === undefined && this.length ) {				data = jQuery.data( this[0], key );			}			return data === undefined && parts[1] ?				this.data( parts[0] ) :				data;		} else {			return this.trigger("setData" + parts[1] + "!", [parts[0], value]).each(function() {				jQuery.data( this, key, value );			});		}	},	removeData: function( key ) {		return this.each(function() {			jQuery.removeData( this, key );		});	}});jQuery.extend({	queue: function( elem, type, data ) {		if ( !elem ) {			return;		}		type = (type || "fx") + "queue";		var q = jQuery.data( elem, type );		// Speed up dequeue by getting out quickly if this is just a lookup		if ( !data ) {			return q || [];		}		if ( !q || jQuery.isArray(data) ) {			q = jQuery.data( elem, type, jQuery.makeArray(data) );		} else {			q.push( data );		}		return q;	},	dequeue: function( elem, type ) {		type = type || "fx";		var queue = jQuery.queue( elem, type ), fn = queue.shift();		// If the fx queue is dequeued, always remove the progress sentinel		if ( fn === "inprogress" ) {			fn = queue.shift();		}		if ( fn ) {			// Add a progress sentinel to prevent the fx queue from being			// automatically dequeued			if ( type === "fx" ) {				queue.unshift("inprogress");			}			fn.call(elem, function() {				jQuery.dequeue(elem, type);			});		}	}});jQuery.fn.extend({	queue: function( type, data ) {		if ( typeof type !== "string" ) {			data = type;			type = "fx";		}		if ( data === undefined ) {			return jQuery.queue( this[0], type );		}		return this.each(function( i, elem ) {			var queue = jQuery.queue( this, type, data );			if ( type === "fx" && queue[0] !== "inprogress" ) {				jQuery.dequeue( this, type );			}		});	},	dequeue: function( type ) {		return this.each(function() {			jQuery.dequeue( this, type );		});	},	// Based off of the plugin by Clint Helfers, with permission.	// http://blindsignals.com/index.php/2009/07/jquery-delay/	delay: function( time, type ) {		time = jQuery.fx ? jQuery.fx.speeds[time] || time : time;		type = type || "fx";		return this.queue( type, function() {			var elem = this;			setTimeout(function() {				jQuery.dequeue( elem, type );			}, time );		});	},	clearQueue: function( type ) {		return this.queue( type || "fx", [] );	}});var rclass = /[\n\t]/g,	rspace = /\s+/,	rreturn = /\r/g,	rspecialurl = /href|src|style/,	rtype = /(button|input)/i,	rfocusable = /(button|input|object|select|textarea)/i,	rclickable = /^(a|area)$/i,	rradiocheck = /radio|checkbox/;jQuery.fn.extend({	attr: function( name, value ) {		return access( this, name, value, true, jQuery.attr );	},	removeAttr: function( name, fn ) {		return this.each(function(){			jQuery.attr( this, name, "" );			if ( this.nodeType === 1 ) {				this.removeAttribute( name );			}		});	},	addClass: function( value ) {		if ( jQuery.isFunction(value) ) {			return this.each(function(i) {				var self = jQuery(this);				self.addClass( value.call(this, i, self.attr("class")) );			});		}		if ( value && typeof value === "string" ) {			var classNames = (value || "").split( rspace );			for ( var i = 0, l = this.length; i < l; i++ ) {				var elem = this[i];				if ( elem.nodeType === 1 ) {					if ( !elem.className ) {						elem.className = value;					} else {						var className = " " + elem.className + " ", setClass = elem.className;						for ( var c = 0, cl = classNames.length; c < cl; c++ ) {							if ( className.indexOf( " " + classNames[c] + " " ) < 0 ) {								setClass += " " + classNames[c];							}						}						elem.className = jQuery.trim( setClass );					}				}			}		}		return this;	},	removeClass: function( value ) {		if ( jQuery.isFunction(value) ) {			return this.each(function(i) {				var self = jQuery(this);				self.removeClass( value.call(this, i, self.attr("class")) );			});		}		if ( (value && typeof value === "string") || value === undefined ) {			var classNames = (value || "").split(rspace);			for ( var i = 0, l = this.length; i < l; i++ ) {				var elem = this[i];				if ( elem.nodeType === 1 && elem.className ) {					if ( value ) {						var className = (" " + elem.className + " ").replace(rclass, " ");						for ( var c = 0, cl = classNames.length; c < cl; c++ ) {							className = className.replace(" " + classNames[c] + " ", " ");						}						elem.className = jQuery.trim( className );					} else {						elem.className = "";					}				}			}		}		return this;	},	toggleClass: function( value, stateVal ) {		var type = typeof value, isBool = typeof stateVal === "boolean";		if ( jQuery.isFunction( value ) ) {			return this.each(function(i) {				var self = jQuery(this);				self.toggleClass( value.call(this, i, self.attr("class"), stateVal), stateVal );			});		}		return this.each(function() {			if ( type === "string" ) {				// toggle individual class names				var className, i = 0, self = jQuery(this),					state = stateVal,					classNames = value.split( rspace );				while ( (className = classNames[ i++ ]) ) {					// check each className given, space seperated list					state = isBool ? state : !self.hasClass( className );					self[ state ? "addClass" : "removeClass" ]( className );				}			} else if ( type === "undefined" || type === "boolean" ) {				if ( this.className ) {					// store className if set					jQuery.data( this, "__className__", this.className );				}				// toggle whole className				this.className = this.className || value === false ? "" : jQuery.data( this, "__className__" ) || "";			}		});	},	hasClass: function( selector ) {		var className = " " + selector + " ";		for ( var i = 0, l = this.length; i < l; i++ ) {			if ( (" " + this[i].className + " ").replace(rclass, " ").indexOf( className ) > -1 ) {				return true;			}		}		return false;	},	val: function( value ) {		if ( value === undefined ) {			var elem = this[0];			if ( elem ) {				if ( jQuery.nodeName( elem, "option" ) ) {					return (elem.attributes.value || {}).specified ? elem.value : elem.text;				}				// We need to handle select boxes special				if ( jQuery.nodeName( elem, "select" ) ) {					var index = elem.selectedIndex,						values = [],						options = elem.options,						one = elem.type === "select-one";					// Nothing was selected					if ( index < 0 ) {						return null;					}					// Loop through all the selected options					for ( var i = one ? index : 0, max = one ? index + 1 : options.length; i < max; i++ ) {						var option = options[ i ];						if ( option.selected ) {							// Get the specifc value for the option							value = jQuery(option).val();							// We don't need an array for one selects							if ( one ) {								return value;							}							// Multi-Selects return an array							values.push( value );						}					}					return values;				}				// Handle the case where in Webkit "" is returned instead of "on" if a value isn't specified				if ( rradiocheck.test( elem.type ) && !jQuery.support.checkOn ) {					return elem.getAttribute("value") === null ? "on" : elem.value;				}								// Everything else, we just grab the value				return (elem.value || "").replace(rreturn, "");			}			return undefined;		}		var isFunction = jQuery.isFunction(value);		return this.each(function(i) {			var self = jQuery(this), val = value;			if ( this.nodeType !== 1 ) {				return;			}			if ( isFunction ) {				val = value.call(this, i, self.val());			}			// Typecast each time if the value is a Function and the appended			// value is therefore different each time.			if ( typeof val === "number" ) {				val += "";			}			if ( jQuery.isArray(val) && rradiocheck.test( this.type ) ) {				this.checked = jQuery.inArray( self.val(), val ) >= 0;			} else if ( jQuery.nodeName( this, "select" ) ) {				var values = jQuery.makeArray(val);				jQuery( "option", this ).each(function() {					this.selected = jQuery.inArray( jQuery(this).val(), values ) >= 0;				});				if ( !values.length ) {					this.selectedIndex = -1;				}			} else {				this.value = val;			}		});	}});jQuery.extend({	attrFn: {		val: true,		css: true,		html: true,		text: true,		data: true,		width: true,		height: true,		offset: true	},			attr: function( elem, name, value, pass ) {		// don't set attributes on text and comment nodes		if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 ) {			return undefined;		}		if ( pass && name in jQuery.attrFn ) {			return jQuery(elem)[name](value);		}		var notxml = elem.nodeType !== 1 || !jQuery.isXMLDoc( elem ),			// Whether we are setting (or getting)			set = value !== undefined;		// Try to normalize/fix the name		name = notxml && jQuery.props[ name ] || name;		// Only do all the following if this is a node (faster for style)		if ( elem.nodeType === 1 ) {			// These attributes require special treatment			var special = rspecialurl.test( name );			// Safari mis-reports the default selected property of an option			// Accessing the parent's selectedIndex property fixes it			if ( name === "selected" && !jQuery.support.optSelected ) {				var parent = elem.parentNode;				if ( parent ) {					parent.selectedIndex;						// Make sure that it also works with optgroups, see #5701					if ( parent.parentNode ) {						parent.parentNode.selectedIndex;					}				}			}			// If applicable, access the attribute via the DOM 0 way			if ( name in elem && notxml && !special ) {				if ( set ) {					// We can't allow the type property to be changed (since it causes problems in IE)					if ( name === "type" && rtype.test( elem.nodeName ) && elem.parentNode ) {						jQuery.error( "type property can't be changed" );					}					elem[ name ] = value;				}				// browsers index elements by id/name on forms, give priority to attributes.				if ( jQuery.nodeName( elem, "form" ) && elem.getAttributeNode(name) ) {					return elem.getAttributeNode( name ).nodeValue;				}				// elem.tabIndex doesn't always return the correct value when it hasn't been explicitly set				// http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/				if ( name === "tabIndex" ) {					var attributeNode = elem.getAttributeNode( "tabIndex" );					return attributeNode && attributeNode.specified ?						attributeNode.value :						rfocusable.test( elem.nodeName ) || rclickable.test( elem.nodeName ) && elem.href ?							0 :							undefined;				}				return elem[ name ];			}			if ( !jQuery.support.style && notxml && name === "style" ) {				if ( set ) {					elem.style.cssText = "" + value;				}				return elem.style.cssText;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -