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

📄 jquery.js

📁 应用JavaScript结合jquery写的小demo
💻 JS
📖 第 1 页 / 共 3 页
字号:
		if ( ret && ret[0] == context ) ret.shift();		done = jQuery.merge( done, ret );			return done;	},		getAll: function(o,r) {		r = r || [];		var s = o.childNodes;		for ( var i = 0; i < s.length; i++ )			if ( s[i].nodeType == 1 ) {				r.push( s[i] );				jQuery.getAll( s[i], r );			}		return r;	},		attr: function(elem, name, value){		var fix = {			"for": "htmlFor",			"class": "className",			"float": "cssFloat",			innerHTML: "innerHTML",			className: "className",			value: "value",			disabled: "disabled",			checked: "checked"		};		if ( fix[name] ) {			if ( value != undefined ) elem[fix[name]] = value;			return elem[fix[name]];		} else if ( elem.getAttribute ) {			if ( value != undefined ) elem.setAttribute( name, value );			return elem.getAttribute( name, 2 );		} else {			name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});			if ( value != undefined ) elem[name] = value;			return elem[name];		}	},	// The regular expressions that power the parsing engine	parse: [		// Match: [@value='test'], [@foo]		[ "\\[ *(@)S *([!*$^=]*) *Q\\]", 1 ],		// Match: [div], [div p]		[ "(\\[)Q\\]", 0 ],		// Match: :contains('foo')		[ "(:)S\\(Q\\)", 0 ],		// Match: :even, :last-chlid		[ "([:.#]*)S", 0 ]	],		filter: function(t,r,not) {		// Figure out if we're doing regular, or inverse, filtering		var g = not !== false ? jQuery.grep :			function(a,f) {return jQuery.grep(a,f,true);};				while ( t && /^[a-z[({<*:.#]/i.test(t) ) {			var p = jQuery.parse;			for ( var i = 0; i < p.length; i++ ) {				var re = new RegExp( "^" + p[i][0]					// Look for a string-like sequence					.replace( 'S', "([a-z*_-][a-z0-9_-]*)" )					// Look for something (optionally) enclosed with quotes					.replace( 'Q', " *'?\"?([^'\"]*?)'?\"? *" ), "i" );				var m = re.exec( t );				if ( m ) {					// Re-organize the match					if ( p[i][1] )						m = ["", m[1], m[3], m[2], m[4]];					// Remove what we just matched					t = t.replace( re, "" );					break;				}			}				// :not() is a special case that can be optomized by			// keeping it out of the expression list			if ( m[1] == ":" && m[2] == "not" )				r = jQuery.filter(m[3],r,false).r;						// Otherwise, find the expression to execute			else {				var f = jQuery.expr[m[1]];				if ( f.constructor != String )					f = jQuery.expr[m[1]][m[2]];									// Build a custom macro to enclose it				eval("f = function(a,i){" + 					( m[1] == "@" ? "z=jQuery.attr(a,m[3]);" : "" ) + 					"return " + f + "}");								// Execute it against the current filter				r = g( r, f );			}		}			// Return an array of filtered elements (r)		// and the modified expression string (t)		return { r: r, t: t };	},	trim: function(t){		return t.replace(/^\s+|\s+$/g, "");	},	parents: function( elem ){		var matched = [];		var cur = elem.parentNode;		while ( cur && cur != document ) {			matched.push( cur );			cur = cur.parentNode;		}		return matched;	},	sibling: function(elem, pos, not) {		var elems = [];		var siblings = elem.parentNode.childNodes;		for ( var i = 0; i < siblings.length; i++ ) {			if ( not === true && siblings[i] == elem ) continue;			if ( siblings[i].nodeType == 1 )				elems.push( siblings[i] );			if ( siblings[i] == elem )				elems.n = elems.length - 1;		}		return jQuery.extend( elems, {			last: elems.n == elems.length - 1,			cur: pos == "even" && elems.n % 2 == 0 || pos == "odd" && elems.n % 2 || elems[pos] == elem,			prev: elems[elems.n - 1],			next: elems[elems.n + 1]		});	},	merge: function(first, second) {		var result = [];				// Move b over to the new array (this helps to avoid		// StaticNodeList instances)		for ( var k = 0; k < first.length; k++ )			result[k] = first[k];			// Now check for duplicates between a and b and only		// add the unique items		for ( var i = 0; i < second.length; i++ ) {			var noCollision = true;						// The collision-checking process			for ( var j = 0; j < first.length; j++ )				if ( second[i] == first[j] )					noCollision = false;							// If the item is unique, add it			if ( noCollision )				result.push( second[i] );		}			return result;	},	grep: function(elems, fn, inv) {		// If a string is passed in for the function, make a function		// for it (a handy shortcut)		if ( fn.constructor == String )			fn = new Function("a","i","return " + fn);					var result = [];				// Go through the array, only saving the items		// that pass the validator function		for ( var i = 0; i < elems.length; i++ )			if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )				result.push( elems[i] );				return result;	},	map: function(elems, fn) {		// If a string is passed in for the function, make a function		// for it (a handy shortcut)		if ( fn.constructor == String )			fn = new Function("a","return " + fn);				var result = [];				// Go through the array, translating each of the items to their		// new value (or values).		for ( var i = 0; i < elems.length; i++ ) {			var val = fn(elems[i],i);			if ( val !== null && val != undefined ) {				if ( val.constructor != Array ) val = [val];				result = jQuery.merge( result, val );			}		}		return result;	},		/*	 * A number of helper functions used for managing events.	 * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.	 */	event: {			// Bind an event to an element		// Original by Dean Edwards		add: function(element, type, handler) {			// For whatever reason, IE has trouble passing the window object			// around, causing it to be cloned in the process			if ( jQuery.browser.msie && element.setInterval != undefined )				element = window;					// Make sure that the function being executed has a unique ID			if ( !handler.guid )				handler.guid = this.guid++;							// Init the element's event structure			if (!element.events)				element.events = {};						// Get the current list of functions bound to this event			var handlers = element.events[type];						// If it hasn't been initialized yet			if (!handlers) {				// Init the event handler queue				handlers = element.events[type] = {};								// Remember an existing handler, if it's already there				if (element["on" + type])					handlers[0] = element["on" + type];			}			// Add the function to the element's handler list			handlers[handler.guid] = handler;						// And bind the global event handler to the element			element["on" + type] = this.handle;				// Remember the function in a global list (for triggering)			if (!this.global[type])				this.global[type] = [];			this.global[type].push( element );		},				guid: 1,		global: {},				// Detach an event or set of events from an element		remove: function(element, type, handler) {			if (element.events)				if (type && element.events[type])					if ( handler )						delete element.events[type][handler.guid];					else						for ( var i in element.events[type] )							delete element.events[type][i];				else					for ( var j in element.events )						this.remove( element, j );		},				trigger: function(type,data,element) {			// Touch up the incoming data			data = data || [];				// Handle a global trigger			if ( !element ) {				var g = this.global[type];				if ( g )					for ( var i = 0; i < g.length; i++ )						this.trigger( type, data, g[i] );				// Handle triggering a single element			} else if ( element["on" + type] ) {				// Pass along a fake event				data.unshift( this.fix({ type: type, target: element }) );					// Trigger the event				element["on" + type].apply( element, data );			}		},				handle: function(event) {			if ( typeof jQuery == "undefined" ) return;			event = event || jQuery.event.fix( window.event );				// If no correct event was found, fail			if ( !event ) return;					var returnValue = true;			var c = this.events[event.type];					for ( var j in c ) {				if ( c[j].apply( this, [event] ) === false ) {					event.preventDefault();					event.stopPropagation();					returnValue = false;				}			}						return returnValue;		},				fix: function(event) {			if ( event ) {				event.preventDefault = function() {					this.returnValue = false;				};							event.stopPropagation = function() {					this.cancelBubble = true;				};			}						return event;		}		}});new function() {	var b = navigator.userAgent.toLowerCase();	// Figure out what browser is being used	jQuery.browser = {		safari: /webkit/.test(b),		opera: /opera/.test(b),		msie: /msie/.test(b) && !/opera/.test(b),		mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)	};	// Check to see if the W3C box model is being used	jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";};jQuery.macros = {	to: {		appendTo: "append",		prependTo: "prepend",		insertBefore: "before",		insertAfter: "after"	},		css: "width,height,top,left,position,float,overflow,color,background".split(","),	filter: [ "eq", "lt", "gt", "contains" ],	attr: {		val: "value",		html: "innerHTML",		id: null,		title: null,		name: null,		href: null,		src: null,		rel: null	},		axis: {		parent: "a.parentNode",		ancestors: jQuery.parents,		parents: jQuery.parents,		next: "jQuery.sibling(a).next",		prev: "jQuery.sibling(a).prev",		siblings: jQuery.sibling,		children: "jQuery.sibling(a.firstChild)"	},	each: {		removeAttr: function( key ) {			this.removeAttribute( key );		},		show: function(){			this.style.display = this.oldblock ? this.oldblock : "";			if ( jQuery.css(this,"display") == "none" )				this.style.display = "block";		},		hide: function(){			this.oldblock = this.oldblock || jQuery.css(this,"display");			if ( this.oldblock == "none" )				this.oldblock = "block";			this.style.display = "none";		},		toggle: function(){			jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ].apply( jQuery(this), arguments );		},		addClass: function(c){			jQuery.className.add(this,c);		},		removeClass: function(c){			jQuery.className.remove(this,c);		},		toggleClass: function( c ){			jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this,c);		},		remove: function(a){			if ( !a || jQuery.filter( a, [this] ).r )				this.parentNode.removeChild( this );		},		empty: function(){			while ( this.firstChild )				this.removeChild( this.firstChild );		},		bind: function( type, fn ) {			if ( fn.constructor == String )				fn = new Function("e", ( !fn.indexOf(".") ? "jQuery(this)" : "return " ) + fn);			jQuery.event.add( this, type, fn );		},		unbind: function( type, fn ) {			jQuery.event.remove( this, type, fn );		},		trigger: function( type, data ) {			jQuery.event.trigger( type, data, this );		}	}};jQuery.init();jQuery.fn.extend({	// We're overriding the old toggle function, so	// remember it for later	_toggle: jQuery.fn.toggle,	toggle: function(a,b) {		// If two functions are passed in, we're		// toggling on a click		return a && b && a.constructor == Function && b.constructor == Function ? this.click(function(e){			// Figure out which function to execute			this.last = this.last == a ? b : a;						// Make sure that clicks stop			e.preventDefault();						// and execute the function			return this.last.apply( this, [e] ) || false;		}) :				// Otherwise, execute the old toggle function		this._toggle.apply( this, arguments );	},
	hover: function(f,g) {				// A private function for haandling mouse 'hovering'		function handleHover(e) {			// Check if mouse(over|out) are still within the same parent element			var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget;				// Traverse up the tree			while ( p && p != this ) p = p.parentNode;						// If we actually just moused on to a sub-element, ignore it			if ( p == this ) return false;						// Execute the right function			return (e.type == "mouseover" ? f : g).apply(this, [e]);		}				// Bind the function to the two event listeners		return this.mouseover(handleHover).mouseout(handleHover);	},	ready: function(f) {		// If the DOM is already ready		if ( jQuery.isReady )			// Execute the function immediately			f.apply( document );					// Otherwise, remember the function for later		else {			// Add the function to the wait list			jQuery.readyList.push( f );		}			return this;	}});jQuery.extend({	/*	 * All the code that makes DOM Ready work nicely.	 */	isReady: false,	readyList: [],		// Handle when the DOM is ready	ready: function() {		// Make sure that the DOM is not already loaded		if ( !jQuery.isReady ) {			// Remember that the DOM is ready			jQuery.isReady = true;						// If there are functions bound, to execute			if ( jQuery.readyList ) {				// Execute all of them				for ( var i = 0; i < jQuery.readyList.length; i++ )					jQuery.readyList[i].apply( document );								// Reset the list of functions				jQuery.readyList = null;			}		}	}});new function(){	var e = ("blur,focus,load,resize,scroll,unload,click,dblclick," +		"mousedown,mouseup,mousemove,mouseover,mouseout,change,reset,select," + 		"submit,keydown,keypress,keyup,error").split(",");	// Go through all the event names, but make sure that	// it is enclosed properly	for ( var i = 0; i < e.length; i++ ) new function(){					var o = e[i];				// Handle event binding		jQuery.fn[o] = function(f){			return f ? this.bind(o, f) : this.trigger(o);		};				// Handle event unbinding		jQuery.fn["un"+o] = function(f){ return this.unbind(o, f); };				// Finally, handle events that only fire once		jQuery.fn["one"+o] = function(f){			// Attach the event listener			return this.each(function(){				var count = 0;				// Add the event				jQuery.event.add( this, o, function(e){					// If this function has already been executed, stop					if ( count++ ) return;									// And execute the bound function					return f.apply(this, [e]);				});			});		};				};		// If Mozilla is used	if ( jQuery.browser.mozilla || jQuery.browser.opera ) {		// Use the handy event callback		document.addEventListener( "DOMContentLoaded", jQuery.ready, false );		// If IE is used, use the excellent hack by Matthias Miller	// http://www.outofhanwell.com/blog/index.php?title=the_window_onload_problem_revisited	} else if ( jQuery.browser.msie ) {			// Only works if you document.write() it		document.write("<scr" + "ipt id=__ie_init defer=true " + 			"src=//:><\/script>");			// Use the defer script hack		var script = document.getElementById("__ie_init");		script.onreadystatechange = function() {			if ( this.readyState != "complete" ) return;			this.parentNode.removeChild( this );			jQuery.ready();		};			// Clear from memory		script = null;		// If Safari  is used	} else if ( jQuery.browser.safari ) {		// Continually check to see if the document.readyState is valid		jQuery.safariTimer = setInterval(function(){			// loaded and complete are both valid states			if ( document.readyState == "loaded" || 				document.readyState == "complete" ) {					// If either one are found, remove the timer				clearInterval( jQuery.safariTimer );				jQuery.safariTimer = null;

⌨️ 快捷键说明

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