2015-10-07 JQuery2

Source: Internet
Author: User

JQuery (2)

Four. Filter Selector

1. $ ("input[type= ' button ')"). Val ("China")//all settings Type=button input, its value is set to China.

Abbreviated ==>$ (": Button"). Val ("China")

List:

$ (": Button") All buttons
$ (": checkbox") All check boxes, <==>$ ("input[type= ' checkbox ']")
$ ("Div:contains (foo)" The elements of the text "foo" are included in all Div
$ (":d isabled") All disabled elements <==>$ ("input[disabled=disabled]"). attr ("value", "AAA");)
$ (": Enable") All elements that are not disabled
$ (": File") All upload files
$ (": input") All form elements
$ (": Selected") Selected items in all drop-down menus
$ (": visible") All visible elements
$ (": Submit") All Submit button

Five. Reverse filtering

$ ("Input:not (: Text)"). Val ("China")//indicates that all input is not a text box, giving it a value = "China".

<==>$ ("input"). Not (": Text"). Val ("China")

Note: p:not (p:hidden) Error

P:not (: Hidden) is correctly//not after the previous result set, that is, not has no other label

Six. Manage Selection results

1. Get the number of elements

$ ("img"). Size ()//Get the number of IMG in all pages

2. Extracting elements

$ ("img[title]") [1] gets all the second element in the img tag that has the title property set .

<==>$ ("Img[title]"). EQ (1)

3. Get the Index

Alert ($ ("div"). Index ($ ("div[title= ' Hello ')"). EQ (1)); Set the "title= Hello" in the second Div, in the index of the entire Div

Gets the index of the current object-----$ (this). index ();

Gets the contents of the current object-----$ (this). text ();

4. Add, remove, and filter elements

$ ("Img[alt], Img[title]"). AddClass ("MyClass")//all IMG tags that have the alt attribute set and all IMG tags that have the Title property set to add a style.

$ ("img"). EQ (3). Removeclass ("MyClass")//Remove fourth IMG myClass style

$ ("Li[title]"). Not ("[TITLE*=ISAAC]") All Li tags that have the title property set, but do not include the Li with Isaac in the title value.

Note: Only generic expressions are available in not ()

Error: $ ("Li[title]"). Not ("IMG[TITLE*=ISAAC]")

Correct: $ ("Li[title]"). Not ("[TITLE*=ISAAC]")

5. Filter elements

$ ("Li"). Filter ("[TITLE*=ISAAC]") <=> $ ("LI[TITLE*=ISAAC]")//filter out the LI tag that contains Isaac in the title property

Note: The parameters in filter can not be directly equal to the match, only the pre-match ^=, after matching &=, any matching *=.

The filter (function) function requires that a Boolean value be returned, which is preserved for elements that return a true value, or otherwise removed.

6.find Find Search

$ ("P"). FIND ("span")//search for span tags in all p tags

7.is returns BOOL

var bhasimge=$ ("Div"). Is ("img")//The page contains an IMG tag in all Div, returns True, and No returns FALSE.

Seven. jquery Chain

1.jQuery statements are linked together

$ ("div"). addclass ("MyClass1"). Filter (function (index) {return index==1| |   $ (this). attr ("id") = = "Fourth"}). addclass ("MyClass2"); attr: Setting Property values

Add a myClass2 style to all div plus myClass1 styles, and then filter out the index=1 or Id=fourth div of the current object.

2.end indicates that the action object is the top level of the current object

$ ("P"). FIND ("span"). AddClass ("MyClass1"). End (). addclass ("MyClass2")//Add MYCLASS1 style to span in P tag, Add myClass2 style to P tag

$ ("P"). FIND ("span"). AddClass ("MyClass1"). AddClass ("MyClass2")///for span in P tag plus myClass1 style and myClass2 style

3.andSelf () indicates that the action object is the current object and its top level

$ ("div"). Find ("P"). addclass ("MyClass1"). Andself (). addclass ("MyClass2")//Add MYCLASS1 style to the p inside Div, Add the MyClass2 style to the P in Div and div

Eight. Properties of the tag

1.each () traversal element

$ (function () {

$ ("div"). each (function (index) {

var i=index+1;

$ (this). attr ("title", "I am the first" +i+ "div")

});

});

2. Get the value of a property

var stitle=$ ("Em:eq (1)"). attr ("title"); Gets the title property of the second EM

$ ("a[href^=http://]"). attr ("target", "_blank"); For a tag whose property href starts with HTTP//, set the property value Target:_blank

$ ("img"). attr ({src: "aaa.jpg", Title: "Ruan MoU", alt: "Unable to display"}); Setting multiple Property values

$ ("div"). EQ (3). Removeattr ("Disabled"); Delete the attribute value for the fourth Div disabled

Note The:<em> label indicates that the text is displayed in italics for the browser

Other:

$ ("div"). EQ (3). CSS ("Color", "red");

$ ("div"). EQ (3). addclass ("D4");

#d4 {

Color: #fff;

}//The result shows the font of the fourth Div is still red, because the CSS set is equal to the >id>class style set in the HTML, its priority is.

You can also set multiple CSS (plus brackets): $ ("div"). EQ (0). css ({"Color": "Black", "font-size": "60px", "height": "100px"});

2015-10-07 JQuery2

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.