jquery common values and traversal methods

First, the drop-down box to obtain the value

--------- "I rarely use the drop-down box, but the registration, and login screening location is quite useful

1) Get the first option value: $ ( "# the Test option: First") Val ();.

2) Gets the last option value: $ ( "# the Test option: Last") Val ();.

3) gets the second option value: $ ( "# the Test option: EQ (1)") Val ();.

4) to obtain the selected value: $ ( "# the Test") Val ();.

Second, select a common father and son, brother nodes

1) .parent (); find a parent element

2) .parents (); find all ancestor elements, not limited to the parent element

3) .children (); find all child elements, will only find a direct child elements, will not return all child elements

4) .contents (); Find all of the following contents, including text and node

5) .prev (); Find a sibling node, not all siblings ------------- "common

6) .prevAll (); before Find all siblings

7) .next (); Find a sibling, not all siblings ----------- "common

8) .nextAll (); siblings look after all

9) .siblings (); Find siblings, in no particular

10) .find (); with jQuery.filter (expr) completely different, jQuery.filter (expr) is selected from the initial part of the object set jQuery, whereas jQuery.find () returns the result, there will be no initial the contents of the collection, such as:. $ ( "p") find ( "span") is to start looking for the element p, equal to $ ( "p span")
Notes: 1.find (), python reptiles for a small partner to that will be frequently used, you can stack look, the disadvantage is the need to find the specified parent or selector (not very big problem) returns a -------------

   2.filter () method to match the reduced element set to match the specified selector element. Database field in front of me blog Django, features matching much, he is screened out qualified all queryset collection --- "returns one or more https://www.cnblogs.com/cybg/p/11943588. html 

Three, jquery array operation

  3.1 determines whether the array

jQuery.inArray (): 

$ .inArray ( "js" , arr); 
arr specified array 
js for the element

  3.2join () to all elements of the array into a string. Elements separated by the specified delimiter.

arr = [ "a", "b", "c", "d", "e" ];
arr.join("-")
a-b-c-d-e

 

Guess you like

Origin www.cnblogs.com/cybg/p/12590936.html
Recommended