📄 jquery.js
字号:
var getComputedStyle = document.defaultView.getComputedStyle( elem, null ); if ( getComputedStyle && !color( elem ) ) ret = getComputedStyle.getPropertyValue( name ); // If the element isn't reporting its values properly in Safari // then some display: none elements are involved else { var swap = [], stack = []; // Locate all of the parent display: none elements for ( var a = elem; a && color(a); a = a.parentNode ) stack.unshift(a); // Go through and make them visible, but in reverse // (It would be better if we knew the exact display type that they had) for ( var i = 0; i < stack.length; i++ ) if ( color( stack[ i ] ) ) { swap[ i ] = stack[ i ].style.display; stack[ i ].style.display = "block"; } // Since we flip the display style, we have to handle that // one special, otherwise get the value ret = name == "display" && swap[ stack.length - 1 ] != null ? "none" : ( getComputedStyle && getComputedStyle.getPropertyValue( name ) ) || ""; // Finally, revert the display styles back for ( var i = 0; i < swap.length; i++ ) if ( swap[ i ] != null ) stack[ i ].style.display = swap[ i ]; } // We should always get a number back from opacity if ( name == "opacity" && ret == "" ) ret = "1"; } else if ( elem.currentStyle ) { var camelCase = name.replace(/\-(\w)/g, function(all, letter){ return letter.toUpperCase(); }); ret = elem.currentStyle[ name ] || elem.currentStyle[ camelCase ]; // From the awesome hack by Dean Edwards // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291 // If we're not dealing with a regular pixel number // but a number that has a weird ending, we need to convert it to pixels if ( !/^\d+(px)?$/i.test( ret ) && /^\d/.test( ret ) ) { // Remember the original values var style = elem.style.left, runtimeStyle = elem.runtimeStyle.left; // Put in the new values to get a computed value out elem.runtimeStyle.left = elem.currentStyle.left; elem.style.left = ret || 0; ret = elem.style.pixelLeft + "px"; // Revert the changed values elem.style.left = style; elem.runtimeStyle.left = runtimeStyle; } } return ret; }, /** @id jQuery.clean **/ clean: function( elems, context ) { var ret = []; context = context || document; // !context.createElement fails in IE with an error but returns typeof 'object' if (typeof context.createElement == 'undefined') context = context.ownerDocument || context[0] && context[0].ownerDocument || document; jQuery.each(elems, function(i, elem){ if ( !elem ) return; if ( elem.constructor == Number ) elem = elem.toString(); // Convert html string into DOM nodes if ( typeof elem == "string" ) { // Fix "XHTML"-style tags in all browsers elem = elem.replace(/(<(\w+)[^>]*?)\/>/g, function(all, front, tag){ return tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i) ? all : front + "></" + tag + ">"; }); // Trim whitespace, otherwise indexOf won't work as expected var tags = jQuery.trim( elem ).toLowerCase(), div = context.createElement("div"); var wrap = // option or optgroup !tags.indexOf("<opt") && [ 1, "<select multiple='multiple'>", "</select>" ] || !tags.indexOf("<leg") && [ 1, "<fieldset>", "</fieldset>" ] || tags.match(/^<(thead|tbody|tfoot|colg|cap)/) && [ 1, "<table>", "</table>" ] || !tags.indexOf("<tr") && [ 2, "<table><tbody>", "</tbody></table>" ] || // <thead> matched above (!tags.indexOf("<td") || !tags.indexOf("<th")) && [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ] || !tags.indexOf("<col") && [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ] || // IE can't serialize <link> and <script> tags normally jQuery.browser.msie && [ 1, "div<div>", "</div>" ] || [ 0, "", "" ]; // Go to html and back, then peel off extra wrappers div.innerHTML = wrap[1] + elem + wrap[2]; // Move to the right depth while ( wrap[0]-- ) div = div.lastChild; // Remove IE's autoinserted <tbody> from table fragments if ( jQuery.browser.msie ) { // String was a <table>, *may* have spurious <tbody> var tbody = !tags.indexOf("<table") && tags.indexOf("<tbody") < 0 ? div.firstChild && div.firstChild.childNodes : // String was a bare <thead> or <tfoot> wrap[1] == "<table>" && tags.indexOf("<tbody") < 0 ? div.childNodes : []; for ( var j = tbody.length - 1; j >= 0 ; --j ) if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length ) tbody[ j ].parentNode.removeChild( tbody[ j ] ); // IE completely kills leading whitespace when innerHTML is used if ( /^\s/.test( elem ) ) div.insertBefore( context.createTextNode( elem.match(/^\s*/)[0] ), div.firstChild ); } elem = jQuery.makeArray( div.childNodes ); } if ( elem.length === 0 && (!jQuery.nodeName( elem, "form" ) && !jQuery.nodeName( elem, "select" )) ) return; if ( elem[0] == undefined || jQuery.nodeName( elem, "form" ) || elem.options ) ret.push( elem ); else ret = jQuery.merge( ret, elem ); }); return ret; }, attr: function( elem, name, value ) { // don't set attributes on text and comment nodes if (!elem || elem.nodeType == 3 || elem.nodeType == 8) return undefined; var fix = jQuery.isXMLDoc( elem ) ? {} : jQuery.props; // Safari mis-reports the default selected property of a hidden option // Accessing the parent's selectedIndex property fixes it if ( name == "selected" && jQuery.browser.safari ) elem.parentNode.selectedIndex; // Certain attributes only work when accessed via the old DOM 0 way if ( fix[ name ] ) { if ( value != undefined ) elem[ fix[ name ] ] = value; return elem[ fix[ name ] ]; } else if ( jQuery.browser.msie && name == "style" ) return jQuery.attr( elem.style, "cssText", value ); else if ( value == undefined && jQuery.browser.msie && jQuery.nodeName( elem, "form" ) && (name == "action" || name == "method") ) return elem.getAttributeNode( name ).nodeValue; // IE elem.getAttribute passes even for style else if ( elem.tagName ) { if ( value != undefined ) { // We can't allow the type property to be changed (since it causes problems in IE) if ( name == "type" && jQuery.nodeName( elem, "input" ) && elem.parentNode ) throw "type property can't be changed"; // convert the value to a string (all browsers do this but IE) see #1070 elem.setAttribute( name, "" + value ); } if ( jQuery.browser.msie && /href|src/.test( name ) && !jQuery.isXMLDoc( elem ) ) return elem.getAttribute( name, 2 ); return elem.getAttribute( name ); // elem is actually elem.style ... set the style } else { // IE actually uses filters for opacity if ( name == "opacity" && jQuery.browser.msie ) { if ( value != undefined ) { // IE has trouble with opacity if it does not have layout // Force it by setting the zoom level elem.zoom = 1; // Set the alpha filter to set the opacity elem.filter = (elem.filter || "").replace( /alpha\([^)]*\)/, "" ) + (parseFloat( value ).toString() == "NaN" ? "" : "alpha(opacity=" + value * 100 + ")"); } return elem.filter && elem.filter.indexOf("opacity=") >= 0 ? (parseFloat( elem.filter.match(/opacity=([^)]*)/)[1] ) / 100).toString() : ""; } name = name.replace(/-([a-z])/ig, function(all, letter){ return letter.toUpperCase(); }); if ( value != undefined ) elem[ name ] = value; return elem[ name ]; } }, /** @id jQuery.trim **/ trim: function( text ) { return (text || "").replace( /^\s+|\s+$/g, "" ); }, /** @id jQuery.makeArray **/ makeArray: function( array ) { var ret = []; // Need to use typeof to fight Safari childNodes crashes if ( typeof array != "array" ) for ( var i = 0, length = array.length; i < length; i++ ) ret.push( array[ i ] ); else ret = array.slice( 0 ); return ret; }, /** @id jQuery.inArray **/ inArray: function( elem, array ) { for ( var i = 0, length = array.length; i < length; i++ ) if ( array[ i ] == elem ) return i; return -1; }, /** @id jQuery.merge **/ merge: function( first, second ) { // We have to loop this way because IE & Opera overwrite the length // expando of getElementsByTagName // Also, we need to make sure that the correct elements are being returned // (IE returns comment nodes in a '*' query) if ( jQuery.browser.msie ) { for ( var i = 0; second[ i ]; i++ ) if ( second[ i ].nodeType != 8 ) first.push( second[ i ] ); } else for ( var i = 0; second[ i ]; i++ ) first.push( second[ i ] ); return first; }, /** @id jQuery.unique **/ unique: function( array ) { var ret = [], done = {}; try { for ( var i = 0, length = array.length; i < length; i++ ) { var id = jQuery.data( array[ i ] ); if ( !done[ id ] ) { done[ id ] = true; ret.push( array[ i ] ); } } } catch( e ) { ret = array; } return ret; }, /** @id jQuery.grep **/ grep: function( elems, callback, inv ) { var ret = []; // Go through the array, only saving the items // that pass the validator function for ( var i = 0, length = elems.length; i < length; i++ ) if ( !inv && callback( elems[ i ], i ) || inv && !callback( elems[ i ], i ) ) ret.push( elems[ i ] ); return ret; }, /** @id jQuery.map **/ map: function( elems, callback ) { var ret = []; // Go through the array, translating each of the items to their // new value (or values). for ( var i = 0, length = elems.length; i < length; i++ ) { var value = callback( elems[ i ], i ); if ( value !== null && value != undefined ) { if ( value.constructor != Array ) value = [ value ]; ret = ret.concat( value ); } } return ret; }});var userAgent = navigator.userAgent.toLowerCase();// Figure out what browser is being usedjQuery.browser = { version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [])[1], safari: /webkit/.test( userAgent ), opera: /opera/.test( userAgent ), msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ), mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )};var styleFloat = jQuery.browser.msie ? "styleFloat" : "cssFloat"; jQuery.extend({ // Check to see if the W3C box model is being used boxModel: !jQuery.browser.msie || document.compatMode == "CSS1Compat", props: { "for": "htmlFor", "class": "className", "float": styleFloat, cssFloat: styleFloat, styleFloat: styleFloat, innerHTML: "innerHTML", className: "className", value: "value", disabled: "disabled", checked: "checked", readonly: "readOnly", selected: "selected", maxlength: "maxLength", selectedIndex: "selectedIndex", defaultValue: "defaultValue", tagName: "tagName", nodeName: "nodeName" }});jQuery.each({ /** @id jQuery.parent **/ parent: function(elem){return elem.parentNode;}, /** @id jQuery.parents **/ parents: function(elem){return jQuery.dir(elem,"parentNode");}, /** @id jQuery.next **/ next: function(elem){return jQuery.nth(elem,2,"nextSibling");}, /** @id jQuery.prev **/ prev: function(elem){return jQuery.nth(elem,2,"previousSibling");}, /** @id jQuery.nextAll **/ nextAll: function(elem){return jQuery.dir(elem,"nextSibling");}, /** @id jQuery.prevAll **/ prevAll: function(elem){return jQuery.dir(elem,"previousSibling");}, /** @id jQuery.siblings **/ siblings: function(elem){return jQuery.sibling(elem.parentNode.firstChild,elem);}, /** @id jQuery.children **/ children: function(elem){return jQuery.sibling(elem.firstChild);}, /** @id jQuery.contents **/ contents: function(elem){return jQuery.nodeName(elem,"iframe")?elem.contentDocument||elem.contentWindow.document:jQuery.makeArray(elem.childNodes);}}, function(name, fn){ jQuery.fn[ name ] = function( selector ) { var ret = jQuery.map( this, fn ); if ( selector && typeof selector == "string" ) ret = jQuery.multiFilter( selector, ret ); return this.pushStack( jQuery.unique( ret ) ); };});jQuery.each({ /** @id jQuery.appendTo **/ appendTo: "append", /** @id jQuery.prependTo **/ prependTo: "prepend", /** @id jQuery.insertBefore **/ insertBefore: "before", /** @id jQuery.insertAfter **/ insertAfter: "after", /** @id jQuery.replaceAll **/ replaceAll: "replaceWith"}, function(name, original){ jQuery.fn[ name ] = function() { var args = arguments; return this.each(function(){ for ( var i = 0, length = args.length; i < length; i++ ) jQuery( args[ i ] )[ original ]( this ); }); };});jQuery.each({ /** @id jQuery.removeAttr **/ removeAttr: function( name ) { jQuery.attr( this, name, "" ); if (this.nodeType == 1) this.removeAttribute( name ); }, /** @id jQuery.addClass **/ addClass: function( classNames ) { jQuery.className.add( this, classNames ); }, /** @id jQuery.removeClass **/ removeClass: function( classNames ) { jQuery.className.remove( this, classNames ); }, /** @id jQuery.toggleClass **/ toggleClass: function( classNames ) { jQuery.className[ jQuery.className.has( this, classNames ) ? "remove" : "add" ]( this, classNames ); },
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -