Introducing jquery
<script language= "javascript" type= "Text/javascript" src= "1.9.0/jquery.js" ></script>
Base Selector
ID Selector
$ ("#my_id")
Element Selector---Eg:div
$ ("element")
Class Selector
$ (". Class")
Select All---eg:$ ("div *")--Choose all div
$ ("*")
Select multiple
$ ("Sele1,sele2,selen")
Parent-child selectors-children including descendants
$("ance desc")
Parent-Child selector-children include only sons
$ ("Parent > Child")
Adjacent selector--only the next adjacent element is fetched
$ ("prev + next")
Adjacent selector--get all adjacent elements
$ ("prev ~ siblings")
eg
$ ("P~span"). CSS ("border", "solid 1px red");
$ ("P~label"). HTML ("We are all fans of Mr. P");
Filter Selector
First filter Selector---Select the one Li
$ ("Li:first")
: EQ (Index) filter Selector--counting starting from 0
Eg: $ ("Li:eq (2)"). CSS ("Background-color", "#60F");
Text content Lookup Filter selector contains (text)
$ ("Li:contains (' Hello ')"). CSS ("Background", "green");
: Has (selector) filter selector
<li><p> I am Mr. P </p></li>
$ ("Li:has (' P ')"). CSS ("Background-color", "Blue");
: Hidden filter Selector: Visible Filter Selector[Attribute=value] Property Selector
<li title= "Fruit" > Watermelon </li>
Eg: $ ("li[title= ' fruit ')"). CSS ("Background-color", "green");
[Attribute!=value] Property Selector[Attribute*=value] Property Selector--Contains
<li title= "Fruit" > Watermelon </li>
Eg: $ ("li[title*= ' water ')"). CSS ("Background-color", "green");
: First-child Sub-element filter Selector--the first Li of each list
$ ("Li:first-child"). CSS ("Background-color", "green");
: Last-child Sub-element filter selector
Form Selector
: Input Form selector--a colon preceded by a spacereturns all table cells , including all <input> tagged form elements, including <textarea>, <select>, and <button> tagged form elements
<form id= "Frmtest" action= "#" >
<input type= "button" value= "input button"/><br/>
<select>
<option>Option</option>
</select><br/>
<textarea rows= "3" cols= "8" ></textarea><br/>
</form>
eg:$ ("#frmTest: Input"). AddClass ("Bg_blue");
: Text selector
$ ("#frmTest: Text"). AddClass ("Bg_blue");
:p assword form password Selector
<input type= "Password" id= "Text2" value= "Password text input box"/>
$ ("#frmTest:p assword"). AddClass ("bg_red");
: Radio radio button Selector
<form id= "Frmtest" action= "#" >
<input type= "button" value= "input button"/><br/>
<input id= "Radio1" type= "Radio"/>
<label for= "Radio1" >
Male </label>
</form>
$ ("#frmTest: Radio"). attr ("Disabled", "true");
: checkbox check box selector
$ ("#frmTest: CheckBox"). attr ("Disabled", "true");
: Submit Button Selector
Typically, only one submit button with a "type" attribute value of "submit" is allowed in a form
<input type= "Submit" value= "point I Submitted"/>
<form id= "Frmtest" action= "#" >
<input type= "button" value= "input button"/><br/>
<input type= "Submit" value= "point I submitted"/><br/>
<button>
Button</button><br/>
</form>
$ ("#frmTest input:submit"). AddClass ("bg_red");-----If there is no input, the button will also add a style.
: Image domain selector
:imageyou can only get <input> image fields using selectors, and you cannot get the image elements in format.
<form id= "Frmtest" action= "#" >
<input type= "image" Src= "http://img.mukewang.com/52b284ea00016b2902590070.jpg"/><br/>
<br/>
<br/>
</form>
<script type= "Text/javascript" >
$ ("#frmTest: Image"). AddClass ("bg_red");
</script>
: Button form pushbutton selector
:buttonThe selector can get and only get the "type" attribute value of "button" <input> and <button> these two kinds of ordinary button elements.
$ ("#frmTest: Button"). AddClass ("Bg_blue");
: Checked selected state selector
$ ("#frmTest: Checked"). attr ("Disabled", true);
<input id= "Radio1" type= "Radio" checked= "checked"/>
<label id= "Label1" for= "Radio1" >
Apple </label>
: Selected selected state selector
The :checked :selected selector can only get the <option> option element in the <select> drop-down list box when compared to the selector
<form id= "Frmtest" action= "#" >
<select id= "Select1" multiple= "multiple" >
<option value= "0" > Apple </option>
<option value= "1" selected= "selected" > Oranges </option>
<option value= "2" > Lychee </option>
<option value= "3" selected= "selected" > Grapes </option>
<option value= "4" > Banana </option>
</select><br/><br/>
<div id= "Tip" ></div>
</form>
<script type= "Text/javascript" >
var $txtOpt = $ ("#frmTest: Selected"). Text ();
$ ("#tip"). HTML ("selection:" + $txtOpt);
</script>
Manipulation of DOM elements
jquery Knowledge points