jquery framework-1. Basic knowledge

Source: Internet
Author: User

about jquery

jquery, as the name implies, is JavaScript and query, and jquery is free and open source. It simplifies querying DOM objects, handling events, animating, interacting with Ajax, and multi-browser JavaScript libraries, with the core idea of write Less,do more (write less and do more).

JQuery Advantages

    1. Small size, smart use (just introduce a JS file).
    2. Convenient selection of page elements (mimicking CSS selectors is more precise and flexible).
    3. Dynamically change page style/page content (manipulate DOM, add and remove styles dynamically).
    4. Control response Events (dynamically add response events).
    5. Provides basic Web page effects, which provide an encapsulated page effect method.
    6. Quickly implement communication (Ajax).
    7. Easy to expand, rich plugins.
    8. Supports chained notation.

Introducing jquery

    1. Introduce a local jquery file via script.
    2. By introducing a CDN above the jquery file.

Version selection

    • 1.x: Compatible with ie678, the most widely used, the official only bug maintenance, function no longer new. So for general projects, the 1.x version is available, and the final version: 1.12.4 (May 20, 2016)
    • 2.x: Incompatible with ie678, few people use, official only bug maintenance, function no longer new. If you do not consider a compatible low version of the browser can use 2.x, final version: 2.2.4 (May 20, 2016)
    • 3.x: Incompatible ie678, only the latest browser is supported. Except for special requirements, the 3.x version is generally not used, and many old jquery plugins do not support this version. Currently this version is the official maintenance version of the main update.

The relationship between jquery and $:

One, jquery selector
    •  id selector: $ ("#box");
    • Tag Selector: $ ("div");
    • descendant selector: $ ("#box   P");
    • :first: Gets the first element.
    • :last: Gets the last element.
    • :even: Matches all elements with an even number of indexed values, counting from 0 onwards.
    • :odd: Matches all elements with an odd index value, counting from 0.
    • :eq (Index): an element that matches a given index value, counting from 0 onwards.
    • :not (selector): Removes all elements that match a given selector.
    • :has (selector): matches the element that contains the element that the selector matches.
ii. jquery attributes and style CSS

Action Properties:

attr (NAME|PROPERTIES|KEY,VALUE|FN): Sets or returns the property value of the selected element.

Removeattr (name): Removes an attribute from each of the matched elements.

Prop (NAME|PROPERTIES|KEY,VALUE|FN): Gets the property value of the first element in a matching element set.

Removeprop (name): Used to delete the property set set by the. Prop () method.

Difference: attr can operate (add and revise) custom node properties, and prop can not (increase and revise). Attr and prop have inconsistent return values for the disabled property of input, attr return disabled or undefined, and prop returns a boolean value .

Operation class:

AddClass (CLASS|FN): Adds the specified class name for each matching element.

Removeclass ([CLASS|FN]): Removes all or the specified class from all matching elements.

Toggleclass (Class|fn[,switch]): Deletes (adds) a class if it exists (does not exist).

What to do:

HTML ([VAL|FN]): Gets the HTML content of the first matching element. This function cannot be used with XML documents. But it can be used in XHTML documents.

Text ([VAL|FN]): Gets the contents of all matching elements. The result is text that is combined with the text content contained by all matching elements. This method is valid for both HTML and XML documents.

Val ([Val|fn|arr]): Gets the current value of the matching element. If multiple selections, an array is returned that contains the selected value.

To manipulate CSS:

CSS (NAME|PRO|[,VAL|FN]): Accesses the style attributes of a matching element.

Operating Position:

offset ([coordinates]): Gets the relative offset of the matching element in the current document. The returned object contains two integer properties: Top and left, measured in pixels. method is only valid for visible elements.

Position (): Gets the offset of the matching element relative to the parent element. The returned object contains two integer properties: Top and left. To calculate the results accurately, use pixel units on the padding, border, and fill properties. This method is valid only for visible elements.

ScrollTop ([Val]): Gets the offset of the top of the matching element relative to the scrollbar. This method is valid for both visible and hidden elements.

ScrollLeft ([Val]): Gets the offset to the left of the matching element relative to the scrollbar. This method is valid for both visible and hidden elements.

Operating Dimensions:

Height ([val|fn]): Gets the height value (px) of the current calculation of the matching element.

Width ([VAL|FN]): Gets the width value (px) that is currently computed for the first matching element.

Innerheight (): Gets the inner area height of the first matched element (including padding, excluding borders). This method is valid for both visible and hidden elements.

Innerwidth (): Gets the inner area width of the first matched element (including padding, excluding borders). This method is valid for both visible and hidden elements.

Outerheight ([options]): Gets the outer height of the first matching element (including padding and borders by default). This method is valid for both visible and hidden elements.

Outerwidth ([options]): Gets the outer width of the first matching element (including padding and borders by default). This method is valid for both visible and hidden elements.

Note: Set options to True to calculate the margin.

Third, filter search

Filter elements:

EQ (index|-index): Gets the nth element. The position of this element is calculated from 0, and if it is negative, the last element in the collection begins the countdown.

First (): Gets the second element.

Last (): Gets the final element.

Hasclass (Class): Checks whether the current element contains a particular class and, if so, returns True.

Has (Expr|ele): Preserves elements that contain specific descendants, and removes elements that do not contain the specified descendants.

Not (EXPR|ELE|FN): Deletes the element that matches the specified expression.

Find elements:

Children ([expr]): Gets a collection of elements that contain all the child elements of each element in the matching element collection. only child elements are considered, regardless of all descendant elements.

Find (Expr|obj|ele): Searches for all child elements that match the specified expression.

Parent ([expr]): Gets a collection of elements that contain a unique parent element for all matching elements.

OffsetParent (): Returns the parent node that the first matching element is used for positioning.

Next ([expr]): Gets a collection of elements that contain a matching set of elements that are immediately behind each element in the next sibling element.

Nextall ([expr]): Finds all sibling elements after the current element.

Prev ([expr]): Gets a collection of elements that contain the first sibling element that is immediately adjacent to each element in the matching element collection.

Prevall ([expr]): Finds all sibling elements before the current element.

Siblings ([expr]): Gets a collection of elements that contain all unique sibling elements of each element in the matching element collection. You can filter by using an optional expression.

Concatenation operation:

Add (Expr|ele|html|obj[,con]): Adds an element that matches an expression to a jquery object. This function can be used to concatenate the result set of an element that matches two expressions respectively. The returned results are always sorted in the order in which the elements appear in the HTML document, rather than simply adding them.

Andself (): Adds the previous selection to the current element.

End (): Go back to the most recent "destructive" operation. That is, the list of matched elements changes to the previous state. Returns an empty set if there were no previous destructive actions. The so-called "destructive" refers to any action that alters the matching jquery element.

iv. jquery Events

Page Loading events:

Ready (FN): Binds a function to execute when the DOM is loaded in readiness to be queried and manipulated. This is the most important function in the event module, because it can greatly improve the responsiveness of the Web application. Simply put, this method is purely an alternative to registering events with the Window.load event.

Binding events:

On (EVENTS,[SELECTOR],[DATA],FN): an event handler that is bound to one or more events on the selection element.

Off (EVENTS,[SELECTOR],[FN]): An event handler that removes one or more events on the selection element.

Bind (TYPE,[DATA],FN): Binds event handlers for specific events of each matching element.

Unbind (TYPE,[DATA|FN]): The reverse operation of BIND () removes the bound event from each matching element. If there are no parameters, all bound events are deleted.

One (TYPE,[DATA],FN): Binds a disposable event handler for each matching element's specific event (like click).

Hover ([over,]out): The first function that is specified is triggered when the mouse moves over a matching element. When the mouse moves out of this element, the specified second function is triggered.

Click ([[DATA],FN]): Triggers the Click event for each matching element. This function invokes all functions that perform binding to the Click event.

Note: The other event methods are used the same way. For example: MouseOver, Mouseout, DblClick, change, Blur, Focus, KeyDown, KeyUp, KeyPress, MouseDown, MouseUp, MouseMove, MouseEnter , MouseLeave, resize, scroll, select, Submit, unload and so on.

jquery framework-1. Basic knowledge

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.