Attribute:
$ ("P"). addclass (
CSS Style defined in
Class Type); add a style to an element
$ ("IMG"). ATTR ({SRC: ”test.jpg ", alt:" test image "}); add attributes/values to an element. The parameter is map.
((”Img”).attr("”src”, ”test.jpg "); add attributes/values to an element
$ ("IMG"). ATTR ("title", function () {return this. SRC}); add attributes/values to an element
((" 文...html (); obtain the content (elements, text, etc.) in the element)
((" 文.".html ("<B> new stuff </B>"); set content for an element
$ ("Element name"). removeattr ("attribute name") deletes a specified attribute and its value for an element.
$ ("Element name"). removeclass ("class") deletes a specified style for an element
$ ("Element name"). Text (); get the text of this element
$ ("Element name"). Text (value); set the text value of this element to value
$ ("Element name"). toggleclass (class) cancels when the element has a style in the parameter. If it does not exist, set this style.
$ ("Input element name"). Val (); get the value of the input element
$ ("Input element name"). Val (value); set the value of the input element to value
Manipulation:
$ ("Element name"). After (content); add content after the Matching Element
$ ("Element name"). append (content); insert content as the element content to the end of the element
$ ("Element name"). appendto (content); element after content
$ ("Element name"). Before (content );
Method Opposite
$ ("Element name"). Clone (Boolean expression) when the Boolean expression is true, the cloned element (treated as true if there is no parameter)
$ ("Element name"). Empty () sets the content of this element to null
$ ("Element name"). insertafter (content); insert the element to the content
$ ("Element name"). insertbefore (content); insert the element before the content
$ ("Element"). prepend (content); Use content as a part of the element and place it at the beginning of the element.
$ ("Element"). prependto (content); Use this element as a part of content and put it at the beginning of content
$ ("Element"). Remove (); Delete all specified elements
$ ("Element"). Remove ("exp"); Delete all elements containing exp
$ ("Element"). Wrap ("html"); Use HTML to enclose this element
$ ("Element"). Wrap (element); Use element to enclose this element
Traversing:
Add (expr)
Add (HTML)
Add (elements)
Children (expr)
Contains (STR)
End ()
Filter (expression)
Filter)
Find (expr)
Is (expr)
Next (expr)
Not (EL)
Not (expr)
Not (elems)
Parent (expr)
Parents (expr)
Prev (expr)
Siblings (expr)
core:
$ (HTML ). appendto ("body") is equivalent to writing an HTML Code
$ (elems) obtain an element on Dom
$ (function () {........}); Execute a function
$ ("div> p00000000.css (" border ", "1px solid gray"); find the subnode P of all Div and add the style
$ ("Input: Radio", document. forms [0]) The first Search all radio buttons in the form
$. extend (PROP) prop is a jquery Object ,
example:
jque Ry. Extend ({
min: function (a, B) {return a MAX: function (a, B) {return A> B? A: B ;}< BR >});
jquery (expression, [Context])-$ (expression, [Context]); by default, $ () query the DOM elements in the current HTML document.
Each (callback) executes a function using each matching element as the context.
Example: 1
$ ("Span"). Click (function ){
$ ("Li"). Each (function (){
$ (This). toggleclass ("example ");
});
});
Example: 2
$ ("Button"). Click (function (){
$ ("Div"). Each (function (index, domele ){
// Domele = This
((Domele).css ("backgroundcolor", "Yellow ");
If ($ (this). Is ("# Stop ")){
$ ("Span"). Text ("stopped at Div index #" + index );
Return false;
}
});
});
Jquery event:
Ready (FN); $ (document). Ready () Note that there is no onload event in the body; otherwise, this function cannot be executed. You can
Many functions are loaded and executed in the FN order.
BIND (type, [data], FN) binds one or more event processor functions for a specific event that matches an element, such as click. Possible event attributes include: blur, focus, load, resize, scroll, unload, click, dblclick, mousedown, mouseup, mousemove,
Mouseover, mouseout, mouseenter, mouseleave, change, select, submit, keydown, keypress,
Keyup, error
One (type, [data], FN) binds one or more event processor functions for a specific event that matches an element, such as click. In each pair
As shown in the preceding figure, the event processing function is executed only once. Other rules are the same as those of the BIND () function.
Trigger (type, [data]) triggers an event on each matching element.
Triggerhandler (type, [data]) triggers a specific event on an element (specify an event type) and cancelsBrowserDefault action for this event
Unbind ([type], [data]) is unbound from each matching element.
$ ("P"). Unbind () Remove all bound events on all paragraphs
$ ("P"). Unbind ("click") Remove the Click Event on all paragraphs
Hover (over, out) Over and out are all methods. When you move the cursor over a matching element, the specified first function is triggered. When you move the cursor out of this element, the specified second function is triggered.
$ ("P"). Hover (function (){
$ (This). addclass ("over ");
},
Function (){
$ (This). addclass ("out ");
}
);
Toggle (FN, FN) triggers the specified first function if a matching element is clicked. When you click the same element again, the second function is triggered.
$ ("P"). Toggle (function (){
$ (This). addclass ("selected ");
},
Function (){
$ (This). removeclass ("selected ");
}
);
Element event list description
Note: For a function without parameters, the parameter is optional fn. Jquery does not support reset events of form elements.
Event Description supports elements or objects.
Blur () element loses focus a, input, textarea, button, select, label, MAP, Area
Change () user changes the field content input, textarea, select
Click () the mouse clicks almost all elements of an object.
Dblclick () double-click almost all elements of an object
Error () an error occurs when a document or image is loaded. Window, IMG
The focus () element obtains the focus a, input, textarea, button, select, label, map, and area.
Keydown () A keyboard key is pressed by almost all elements
Keypress () A keyboard key is pressed or pressed to almost all elements
Keyup () A keyboard key is released to almost all elements
Load (FN) a page or image is loaded. Window, IMG
Mousedown (FN) a mouse button is pressed by almost all elements
Mousemove (FN) the mouse is moved to almost all elements
Mouseout (FN) move the mouse over an element to remove almost all elements.
Mouseover (FN) move the mouse over a certain element to almost all elements
Mouseup (FN) a mouse button is released to almost all elements
Resize (FN) window orFrameworkAdjusted size window, IFRAME, Frame
Window when scroll (FN) is rolling the visible part of the document
Select () text selected document, input, textarea
The submit () submit button is clicked by Form
Unload (FN) User exit page window
Jquery Ajax method description:
Load (URL, [data], [callback]) loads a remote HTML content to a DOM node.
$ ("#Feeds").Load(”feeds.html ");FileLoad it into the DIV with the ID of feeds
$ ("# Feeds"). Load ("feeds. php", {limit: 25}, function (){
Alert ("the last 25 entries in the feed have been loaded ");
});
Jquery. Get (URL, [data], [callback]) uses get to request a page.
$. Get ("test. cgi", {name: "John", time: "2"}, function (data ){
Alert ("data loaded:" + data );
});
Jquery. getjson (URL, [data], [callback]) uses get to request JSON data.
$. Getjson ("test. js", {name: "John", time: "2"}, function (JSON ){
Alert ("JSON data:" + JSON. Users [3]. Name );
});
Jquery. getscript (URL, [callback]) uses GET requestsRelatedArticleHref = "http://www.eephp.cn/archives/tag/javascript">JavascriptFile and execute.
$. Getscript ("test. js", function (){
Alert ("script loaded and executed .");
});
Jquery. Post (URL, [data], [callback], [type]) uses post to request a page.
Ajaxcomplete (callback) executes a function after an Ajax request is completed. This is an Ajax event
$ ("# MSG"). ajaxcomplete (function (request, settings ){
$ (This). append ("<li> request complete. </LI> ");
});
Ajaxerror (callback) executes a function when an Ajax request fails. This is an Ajax event
$ ("# MSG"). ajaxerror (function (request, settings ){
$ (This). append ("<li> error requesting page" + settings. url + "</LI> ");
});
Ajaxsend (callback) executes a function when an Ajax request is sent. This is an Ajax event
$ ("# MSG"). ajaxsend (function (EVT, request, settings ){
$ (This). append ("<LI <starting request at" + settings. url
+ "</LI <");
});
Ajaxstart (callback) executes a function when an Ajax request starts but is not activated. This is an Ajax event
The loading information is displayed when the Ajax request starts (and is not activated ).
$ ("# Loading"). ajaxstart (function (){
$ (This). Show ();
});
Ajaxstop (callback) executes a function when all Ajax operations are stopped. This is an Ajax event
When all Ajax requests are stopped, the loading information is hidden.
$ ("# Loading"). ajaxstop (function (){
$ (This). Hide ();
});
Ajaxsuccess (callback) executes a function after an Ajax request is successfully completed. This is an Ajax event
When the Ajax request is successfully completed, the information is displayed.
$ ("# MSG"). ajaxsuccess (function (EVT, request, settings ){
$ (This). append ("<li> Successful request! </LI> ");
});
Jquery. ajaxsetup (options) sets global settings for all Ajax requests. View the $. Ajax function to obtain all the options.
Set the default global Ajax request option.
$. Ajaxsetup ({
URL: "/XMLHTTP /",
Global: false,
Type: "post"
});
$. Ajax ({data: mydata });
Serialize () connects a group of input elements by name and value. The correct form element sequence is implemented.
Function showvalues (){
VaR STR = $ ("form"). serialize ();
$ ("# Results"). Text (STR );
}
$ (": Checkbox,: Radio"). Click (showvalues );
$ ("Select"). Change (showvalues );
Showvalues ();
Serializearray () connects all form and form elements (similar to the. serialize () method), but returns a JSON data format.
Obtain a set of values from the form and display them.
Function showvalues (){
VaR fields = $ (": Input"). serializearray ();
Alert (fields );
$ ("# Results"). Empty ();
Jquery. Each (fields, function (I, field ){
$ ("# Results"). append (field. Value + "");
});
}
$ (": Checkbox,: Radio"). Click (showvalues );
$ ("Select"). Change (showvalues );
Showvalues ();
Jquery effects method description
Show () shows hidden matching elements.
Show (speed, [callback]) displays all matching elements in an elegant animation, and triggers a callback function optional after the display is complete.
Hide () hides all matching elements.
Hide (speed, [callback]) hides all matching elements with elegant animations, and triggers a callback function after the display is complete.
Toggle () switches the visible state of the element. If the element is visible, switch to hidden. If the element is hidden,
Switch to visible.
Slidedown (speed, [callback]) dynamically displays all matching elements by changing the height (increasing down). Optional
To trigger a callback function. This animation only adjusts the height of the element, so that the matching element can be
Slide.
Slideup (speed, [callback]) dynamically hides all matching elements by changing the height (decreasing upwards). It is optional after hiding.
Triggers a callback function. This animation only adjusts the height of the element and allows the Matching Element to slide"
.
Slidetoggle (speed, [callback]) switches the visibility of all matching elements through height changes, and triggers an optional response after switching.
Call a function. This animation only adjusts the height of the element, so that the matching element can be hidden in a sliding manner.
Hidden or displayed.
Fadein (speed, [callback]) realizes the fade-in effect of all matching elements by changing the opacity. After the animation is complete, it can be triggered.
Send a callback function. This animation only adjusts the opacity of the element, that is,
The height and width do not change.
Fadeout (speed, [callback]) fades out all matching elements by changing the opacity. After the animation is complete
Send a callback function. This animation only adjusts the opacity of the element, that is,
The height and width do not change.
Fadeto (speed, opacity, [callback]) Incrementally adjusts the opacity of all matching elements to the specified opacity and completes the animation.
Then, a callback function is triggered. This animation only adjusts the opacity of the element, that is,
The height and width of a matched element do not change.
Stop () stops all animations that match the element that are currently running. If an animation is in the queue, it starts immediately.
Queue () gets the first matching element of the animation sequence Reference (Returns a function Array )
Queue (callback) adds an executable function at the end of the event sequence of each matching element as the event function of this element.
Queue (Queue) replaces the original animation sequence of all matching elements with a new animated sequence
Dequeue () executes and removes the animation at the front end of the animation sequence
Animate (Params, [duration], [easing], [callback]) is a function used to create a custom animation.
Animate (Params, options) is another way to create a custom animation. Same as above.
Jquery traversing method description
Eq (INDEX) obtains an element at the specified position from the matched element set, and the index starts from 0.
Filter (expr) returns a set of elements that match the specified expression. You can use the "," sign to separate multiple expr for filtering multiple conditions.
Filter (FN) uses a special function as a filter condition to remove unmatched elements from the set.
Is (expr) uses an expression to check the selected element set. If at least one element matches the given
Returns true for the expression.
Map (callback) uses the callback method to call a group of elements in the jquery object. Conversion And add it to a jquery array.
Not (expr) removes the elements that match the specified expression from the matched element set.
Slice (START, [end]) obtains a subset from the Matching Element Set, which is the same as the Slice Method of the built-in array.
Add (expr) adds the elements matching the expression to the jquery object.
Children ([expr]) obtains a set of elements that contain all child elements of each element in a matched element set. Optional Filters
This method will match only the matching elements (including only the element nodes, not the text nodes ).
CONTENTS () obtains a set of all child nodes of each element in a matched element set (only including element nodes, not
Including text nodes). If the element is IFRAME, the document element is obtained.
Find (expr) Search All elements that match the specified expression.
Next ([expr]) gets a set of elements next to each element in the matched element set.
Nextall ([expr]) obtains a set of elements that contain all the following peer elements of each element in the matched element set.
Parent ([expr]) obtains a set of elements that contain the unique parent element of all matching elements.
Parents ([expr]) obtains a set of elements (excluding the root element) that contain the unique ancestor element of all matching elements ).
Prev ([expr]) obtains a set of elements that match the previous generation element next to each element in the element set.
Prevall ([expr]) obtains a set of elements that contain all the previous peer elements of each element in the matched element set.
Siblings ([expr]) obtains an element set of all peer elements of each element in a matched element set.
Andself () adds the previous Matching Element Set to the current set
Obtain all DIV elements and P elements, and add border class attributes. Obtain the P element of all DIV elements,
Add background class attributes
$ ("Div"). Find ("p"). andself (). addclass ("border ");
$ ("Div"). Find ("p"). addclass ("background ");
End () ends the current operation and returns to the previous operation of the current operation.
Locate the span element set in all P elements, return the P element set, and add the CSS attribute.
Vertex (fig fig ("border", "2px red solid ");
Jquery selectors method description
Basic Selector
$ ("# Mydiv") matches a unique element with this ID value
$ ("Div") matches all elements of the specified name
$ (". Myclass") matches all elements with this class style Value
$ ("*") Matches all elements
$ ("Div, span, P. myclass") combines all matched selectors
Cascade Selector
$ ("Form input") descendant selector, select all child nodes of ancestor
$ ("# Main> *") Child selector, select all child nodes of the parent
$ ("Label + input") Select the next node of Prev
$ ("# Prev ~ Div ") compatriot selector, select all compatriot nodes of Prev
Basic filter Selector
$ ("TR: First") matches the first selected Element
$ ("TR: Last") matches the last selected Element
$ ("Input: Not (: checked) + span") filters out all elements matching the selector from the original element set (here there is a temporary selector)
$ ("TR: Even") matches all elements in the even position of the Set (starting from 0)
$ ("TR: odd") matches all elements at the odd position in the Set (starting from 0)
$ ("TD: eq (2)") matches the elements at the specified position in the Set (starting from 0)
$ ("TD: GT (4)") matches all elements after a specified position in the Set (starting from 0)
$ ("TD: Gl (4)") matches all elements before the specified position in the Set (starting from 0)
$ (": Header") matches all titles
$ ("Div: animated") matches all elements of all running animations
Content Filter Selector
$ ("Div: Contains ('john')") matches all elements containing the specified text
$ ("TD: empty") matches all empty elements (elements containing only text are not empty)
$ ("Div: Has (p)") matches all elements containing at least one selector from the original element set again
$ ("TD: parent") matches all non-null elements (elements containing text are also considered)
$ ("Div: hidden") matches all hidden elements, including the hidden fields of the form.
$ ("Div: visible") matches all visible elements
Attribute filter Selector
$ ("Div [ID]") matches all elements with the specified attribute
$ ("Input [name = 'newsletter ']") matches all elements with specified attribute values.
$ ("Input [name! = 'Newsletter '] ") matches all elements that do not have the specified attribute value.
$ ("Input [name ^ = 'News']") matches all elements whose specified attribute values start with value.
$ ("Input [name $ = 'Letter ']") matches all elements whose values end with values.
$ ("Input [name * = 'man']") matches all elements whose specified property value contains the value character.
$ ("Input [ID] [name $ = 'man']") matches all elements that match multiple selectors at the same time.
Child element filter Selector
$ ("Ul Li: Nth-child (2 )"),
$ ("Ul Li: Nth-child (ODD)") matches the nth child element of the parent Element
$ ("Ul Li: Nth-child (3N + 1 )")
$ ("Div span: First-child") matches the 1st child element of the parent Element
$ ("Div span: Last-Child") matches the last child element of the parent Element
$ ("Div button: Only-Child") matches the unique child element of the parent element.
Form element Selector
$ (": Input") matches all form input elements, including all types of input, textarea, select, And button
$ (": Text") matches all input elements of the text type.
$ (": Password") matches all input elements of the password type.
$ (": Radio") matches all input elements of the radio type.
$ (": Checkbox") matches all input elements whose types are checkbox.
$ (": Submit") matches all input elements of the submit type.
$ (": Image") matches all input elements of the image type.
$ (": Reset") matches all input elements whose types are reset.
$ (": Button") matches all input elements of the button type.
$ (": File") matches all input elements whose types are file.
$ (": Hidden") matches the hidden fields of all input elements or forms of the type "hidden ".
Form element filter Selector
$ (": Enabled") matches all operable form elements
$ (": Disabled") matches all form elements that cannot be operated
$ (": Checked") matches all selected elements
$ ("Select option: Selected") matches all selected elements
Jquery CSS
CSS (name) accesses the style attribute of the First Matching Element.
CSS (properties) sets a "name/value pair" object as the style attribute of all matching elements.
$ ("p "). hover (function () {
callback (this).css ({backgroundcolor: "yellow", fontweight: "bolder"});
}, function () {
var cssobj = {
backgroundcolor: "# DDD",
fontweight: "",
color: "RGB (244) "
}< br> comment (this).css (cssobj);
});
CSS (name, value) among all matching elements, set the value of a style attribute.
offset () gets the position of the First Matching Element relative to the current visible window. The returned object has two attributes:
top and left. The attribute value is an integer. This function can only be used for visible elements.
var P = $ ("P: Last");
var offset = P. offset ();
p.html ("Left:" + offset. left + ", top:" + offset. top);
width () gets the width value of the First Matching Element.
width (VAL) sets the specified width value for each matching element.
height () gets the height value of the First Matching Element.
height (VAL) sets the specified height value for each matching element.
jquery utilities method description
jquery. browser
. indicates ie
jquery. browser. version: reads the version information of your browser.
jquery. boxmodel checks whether the browser displays the current page based on W3C CSS Box Model
jquery. isfunction (OBJ) checks whether the passed parameter is a function
function stub () {}< br> var objs = [
function (){},
{X: 15, Y: 20},
null,
stub,
"function"
];
jquery. each (objs, F Unction (I) {
var isfunc = jquery. isfunction (objs [I]);
$ ("span: eq (" + I + ")"). text (isfunc);
});
jquery. trim (STR) clears spaces at both ends of a string and uses regular expressions to clear spaces at both ends of a given character.
jquery. each (object, callback) is a common iterator that can be used to seamlessly iterate objects and arrays.
jquery. extend (target, object1, [objectn]) extends an object, modifies the original object, and returns it. This is a powerful tool inherited by implementation.
, this inheritance is implemented by passing values, rather than the
prototype chain method in JavaScript.
merge settings and options objects, and return the modified settings object
var settings = {validate: false, limit: 5, name: "Foo "};
var Options = {validate: True, name: "BAR"};
jquery. extend (settings, options);
Merge the ults and options objects. The defaults object is not modified. Options object Value
The value of the ults object is passed to empty.
VaR empty = {}
VaR defaults = {validate: false, limit: 5, name: "Foo "};
VaR Options = {validate: True, name: "BAR "};
VaR settings = $. Extend (empty, defaults, options );
Jquery. grep (array, callback, [invert]) removes items in the array using a filter function
$. Grep ([0, 1, 2], function (n, I ){
Return n> 0;
});
Jquery. makearray (OBJ) converts an object similar to an array into a real array.
Converts the selected Div element set to an array.
VaR arr = jquery. makearray (document. getelementsbytagname ("Div "));
Arr. Reverse (); // use an array method on List of DOM elements
$ (ARR). appendto (document. Body );
Jquery. Map (array, callback) uses a method to modify the items in an array, and then returns a new array.
Jquery. inarray (value, array) returns the position of value in the array. If no value is found,-1 is returned.
Jquery. Unique (array) deletes all repeated elements in the array and returns the sorted array.