I am a small white, fresh graduates, previously used jquery, the recent project to use jquery. In the process of doing a lot of detours, non-stop search. Summed up a number of uses for your reference:
The most basic selector syntax includes: ID, class, label, attribute, which is consistent with the CSS selector.
ID selector to add # before ID, such as to select a DIV element with ID mydivid (<div id= "Mydivid" ></div>) can write this:
Copy Code code as follows:
D is not repeatable, so the ID selector selects a jquery object.
The class selector points (.) in front of class, for example, to select an INPUT element with class Myinputclass (<input type= "text" class= "Myinputclass"/>) can be written like this:
Copy Code code as follows:
Class can be repeated, so the class selector can be a class of elements, that is, a good number of elements, so the jquery selection is the array, you can refer to the subscript to select each element:
Copy Code code as follows:
for (var i = 0; I < $ (". Myinputclass"). Length; i++) {$ (". Myinputclass") [I];}
This allows you to iterate through each element.
Tag Selector directly write tag type, such as to select a paragraph p tag (<p></p>) can write:
Copy Code code as follows:
The tag Selector is also an array, selecting all the P tag elements, or iterating through all the elements in the above method.
The property selector is preceded by a square bracket ([]), such as to select an element containing Name= "Xxname", which can be written like this:
Copy Code code as follows:
In this case, the selection is also an array, because name can be duplicated.
ID selector can select an element accurately, but in development we may have to choose a set of elements, how to accurately select the elements we want, in fact, several selectors can be mixed use:
Copy Code code as follows:
<div id= "Attrvaluetab" >
<span style= "White-space:pre" > </span><p>
<span style= "White-space:pre" > </span><input type= "button" value= "OK"/> <input "text" value = "Odd"/> <input type= "text" value= "even"/>
<span style= "White-space:pre" > </span></p>
<span style= "White-space:pre" > </span><p>
<span style= "White-space:pre" > </span><input type= "button" value= "Cancel"/> <input "text" value = "Odd"/> <input type= "text" value= "even"/>
<span style= "White-space:pre" > </span></p>
</div>
For example, we want to select an even number of text labels, that is, a even text box. We can choose this way:
First select the div, and then select P, and then select the text box type= "text", and then select an even number of places:
Copy Code code as follows:
$ ("#attrValueTab p input[type= ' text ']:even");
Portfolio selection is very useful in development. You can use the following method to select a button that is checked or a checkbox element:
Copy Code code as follows:
$ ("Input[name= ' Avdefvalue_input ']:checked");