📄 jquery.js
字号:
*/ clone: function(deep) { // Need to remove events on the element and its descendants var $this = this.add(this.find("*")); $this.each(function() { this._$events = {}; for (var type in this.$events) this._$events[type] = jQuery.extend({},this.$events[type]); }).unbind(); // Do the clone var r = this.pushStack( jQuery.map( this, function(a){ return a.cloneNode( deep != undefined ? deep : true ); }) ); // Add the events back to the original and its descendants $this.each(function() { var events = this._$events; for (var type in events) for (var handler in events[type]) jQuery.event.add(this, type, events[type][handler], events[type][handler].data); this._$events = null; }); // Return the cloned set return r; }, /** * Removes all elements from the set of matched elements that do not * match the specified expression(s). This method is used to narrow down * the results of a search. * * Provide a comma-separated list of expressions to apply multiple filters at once. * * @example $("p").filter(".selected") * @before <p class="selected">Hello</p><p>How are you?</p> * @result [ <p class="selected">Hello</p> ] * @desc Selects all paragraphs and removes those without a class "selected". * * @example $("p").filter(".selected, :first") * @before <p>Hello</p><p>Hello Again</p><p class="selected">And Again</p> * @result [ <p>Hello</p>, <p class="selected">And Again</p> ] * @desc Selects all paragraphs and removes those without class "selected" and being the first one. * * @name filter * @type jQuery * @param String expression Expression(s) to search with. * @cat DOM/Traversing */ /** * Removes all elements from the set of matched elements that do not * pass the specified filter. This method is used to narrow down * the results of a search. * * @example $("p").filter(function(index) { * return $("ol", this).length == 0; * }) * @before <p><ol><li>Hello</li></ol></p><p>How are you?</p> * @result [ <p>How are you?</p> ] * @desc Remove all elements that have a child ol element * * @name filter * @type jQuery * @param Function filter A function to use for filtering * @cat DOM/Traversing */ filter: function(t) { return this.pushStack( jQuery.isFunction( t ) && jQuery.grep(this, function(el, index){ return t.apply(el, [index]) }) || jQuery.multiFilter(t,this) ); }, /** * Removes the specified Element from the set of matched elements. This * method is used to remove a single Element from a jQuery object. * * @example $("p").not( $("#selected")[0] ) * @before <p>Hello</p><p id="selected">Hello Again</p> * @result [ <p>Hello</p> ] * @desc Removes the element with the ID "selected" from the set of all paragraphs. * * @name not * @type jQuery * @param Element el An element to remove from the set * @cat DOM/Traversing */ /** * Removes elements matching the specified expression from the set * of matched elements. This method is used to remove one or more * elements from a jQuery object. * * @example $("p").not("#selected") * @before <p>Hello</p><p id="selected">Hello Again</p> * @result [ <p>Hello</p> ] * @desc Removes the element with the ID "selected" from the set of all paragraphs. * * @name not * @type jQuery * @param String expr An expression with which to remove matching elements * @cat DOM/Traversing */ /** * Removes any elements inside the array of elements from the set * of matched elements. This method is used to remove one or more * elements from a jQuery object. * * Please note: the expression cannot use a reference to the * element name. See the two examples below. * * @example $("p").not( $("div p.selected") ) * @before <div><p>Hello</p><p class="selected">Hello Again</p></div> * @result [ <p>Hello</p> ] * @desc Removes all elements that match "div p.selected" from the total set of all paragraphs. * * @name not * @type jQuery * @param jQuery elems A set of elements to remove from the jQuery set of matched elements. * @cat DOM/Traversing */ not: function(t) { return this.pushStack( t.constructor == String && jQuery.multiFilter(t, this, true) || jQuery.grep(this, function(a) { return ( t.constructor == Array || t.jquery ) ? jQuery.inArray( a, t ) < 0 : a != t; }) ); }, /** * Adds more elements, matched by the given expression, * to the set of matched elements. * * @example $("p").add("span") * @before (HTML) <p>Hello</p><span>Hello Again</span> * @result (jQuery object matching 2 elements) [ <p>Hello</p>, <span>Hello Again</span> ] * @desc Compare the above result to the result of <code>$('p')</code>, * which would just result in <code><nowiki>[ <p>Hello</p> ]</nowiki></code>. * Using add(), matched elements of <code>$('span')</code> are simply * added to the returned jQuery-object. * * @name add * @type jQuery * @param String expr An expression whose matched elements are added * @cat DOM/Traversing */ /** * Adds more elements, created on the fly, to the set of * matched elements. * * @example $("p").add("<span>Again</span>") * @before <p>Hello</p> * @result [ <p>Hello</p>, <span>Again</span> ] * * @name add * @type jQuery * @param String html A string of HTML to create on the fly. * @cat DOM/Traversing */ /** * Adds one or more Elements to the set of matched elements. * * @example $("p").add( document.getElementById("a") ) * @before <p>Hello</p><p><span id="a">Hello Again</span></p> * @result [ <p>Hello</p>, <span id="a">Hello Again</span> ] * * @example $("p").add( document.forms[0].elements ) * @before <p>Hello</p><p><form><input/><button/></form> * @result [ <p>Hello</p>, <input/>, <button/> ] * * @name add * @type jQuery * @param Element|Array<Element> elements One or more Elements to add * @cat DOM/Traversing */ add: function(t) { return this.pushStack( jQuery.merge( this.get(), t.constructor == String ? jQuery(t).get() : t.length != undefined && (!t.nodeName || t.nodeName == "FORM") ? t : [t] ) ); }, /** * Checks the current selection against an expression and returns true, * if at least one element of the selection fits the given expression. * * Does return false, if no element fits or the expression is not valid. * * filter(String) is used internally, therefore all rules that apply there * apply here, too. * * @example $("input[@type='checkbox']").parent().is("form") * @before <form><input type="checkbox" /></form> * @result true * @desc Returns true, because the parent of the input is a form element * * @example $("input[@type='checkbox']").parent().is("form") * @before <form><p><input type="checkbox" /></p></form> * @result false * @desc Returns false, because the parent of the input is a p element * * @name is * @type Boolean * @param String expr The expression with which to filter * @cat DOM/Traversing */ is: function(expr) { return expr ? jQuery.multiFilter(expr,this).length > 0 : false; }, /** * Get the content of the value attribute of the first matched element. * * Use caution when relying on this function to check the value of * multiple-select elements and checkboxes in a form. While it will * still work as intended, it may not accurately represent the value * the server will receive because these elements may send an array * of values. For more robust handling of field values, see the * [http://www.malsup.com/jquery/form/#fields fieldValue function of the Form Plugin]. * * @example $("input").val(); * @before <input type="text" value="some text"/> * @result "some text" * * @name val * @type String * @cat DOM/Attributes */ /** * Set the value attribute of every matched element. * * @example $("input").val("test"); * @before <input type="text" value="some text"/> * @result <input type="text" value="test"/> * * @name val * @type jQuery * @param String val Set the property to the specified value. * @cat DOM/Attributes */ val: function( val ) { return val == undefined ? ( this.length ? this[0].value : null ) : this.attr( "value", val ); }, /** * Get the html contents of the first matched element. * This property is not available on XML documents. * * @example $("div").html(); * @before <div><input/></div> * @result <input/> * * @name html * @type String * @cat DOM/Attributes */ /** * Set the html contents of every matched element. * This property is not available on XML documents. * * @example $("div").html("<b>new stuff</b>"); * @before <div><input/></div> * @result <div><b>new stuff</b></div> * * @name html * @type jQuery * @param String val Set the html contents to the specified value. * @cat DOM/Attributes */ html: function( val ) { return val == undefined ? ( this.length ? this[0].innerHTML : null ) : this.empty().append( val ); }, /** * @private * @name domManip * @param Array args * @param Boolean table Insert TBODY in TABLEs if one is not found. * @param Number dir If dir<0, process args in reverse order. * @param Function fn The function doing the DOM manipulation. * @type jQuery * @cat Core */ domManip: function(args, table, dir, fn){ var clone = this.length > 1, a; return this.each(function(){ if ( !a ) { a = jQuery.clean(args, this.ownerDocument); if ( dir < 0 ) a.reverse(); } var obj = this; if ( table && jQuery.nodeName(this, "table") && jQuery.nodeName(a[0], "tr") ) obj = this.getElementsByTagName("tbody")[0] || this.appendChild(document.createElement("tbody")); jQuery.each( a, function(){ fn.apply( obj, [ clone ? this.cloneNode(true) : this ] ); }); }); }};/** * Extends the jQuery object itself. Can be used to add functions into * the jQuery namespace and to [[Plugins/Authoring|add plugin methods]] (plugins). * * @example jQuery.fn.extend({ * check: function() { * return this.each(function() { this.checked = true; }); * }, * uncheck: function() { * return this.each(function() { this.checked = false; }); * } * }); * $("input[@type=checkbox]").check(); * $("input[@type=radio]").uncheck(); * @desc Adds two plugin methods. * * @example jQuery.extend({ * min: function(a, b) { return a < b ? a : b; }, * max: function(a, b) { return a > b ? a : b; } * }); * @desc Adds two functions into the jQuery namespace * * @name $.extend * @param Object prop The object that will be merged into the jQuery object * @type Object * @cat Core *//** * Extend one object with one or more others, returning the original, * modified, object. This is a great utility for simple inheritance. * * @example var settings = { validate: false, limit: 5, name: "foo" }; * var options = { validate: true, name: "bar" }; * jQuery.extend(settings, options); * @result settings == { validate: true, limit: 5, name: "bar" } * @desc Merge settings and options, modifying settings * * @example var defaults = { validate: false, limit: 5, name: "foo" }; * var options = { validate: true, name: "bar" }; * var settings = jQuery.extend({}, defaults, options); * @result settings == { validate: true, limit: 5, name: "bar" } * @desc Merge defaults and options, without modifying the defaults * * @name $.extend * @param Object target The object to extend * @param Object prop1 The object that will be merged into the first. * @param Object propN (optional) More objects to merge into the first * @type Object * @cat JavaScript */jQuery.extend = jQuery.fn.extend = function() { // copy reference to target object var target = arguments[0], a = 1; // extend jQuery itself if only one argument is passed if ( arguments.length == 1 ) { target = this; a = 0; } var prop; while ( (prop = arguments[a++]) != null ) // Extend the base object for ( var i in prop ) target[i] = prop[i]; // Return the modified object return target;};jQuery.extend({ /** * Run this function to give control of the $ variable back * to whichever library first implemented it. This helps to make * sure that jQuery doesn't conflict with the $ object * of other libraries. * * By using this function, you will only be able to access jQuery * using the 'jQuery' variable. For example, where you used to do * $("div p"), you now must do jQuery("div p"). * * @example jQuery.noConflict(); * // Do something with jQuery * jQuery("div p").hide(); * // Do something with another library's $() * $("content").style.display = 'none'; * @desc Maps the original object that was referenced by $ back to $ * * @example jQuery.noConflict(); * (function($) { * $(function() { * // more code using $ as alias to jQuery * }); * })(jQuery); * // other code using $ as an alias to the other library * @desc Reverts the $ alias and then creates and executes a * function to provide the $ as a jQuery alias inside the functions * scope. Inside the function the original $ object is not available. * This works well for most plugins that don't rely on any other library. *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -