1 <!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd ">2 <HTML>3 <Head>4 <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" />5 <title></title>6 <!--Introducing JQuery -7 <Scriptsrc=".. /scripts/jquery.js "type= "Text/javascript"></Script>8 <Scripttype= "Text/javascript">9 //wait for the DOM element to finish loading.Ten $ (document). Ready (function(){ One Alert ("Hello world!"); A }); - </Script> - </Head> the <Body> - </Body> - </HTML>
jquery's chained style of operation
The difference between a jquery object and a DOM object: The jquery object is the object that is produced after wrapping the DOM object, and the methods of the two cannot be used. But the two objects can be converted to each other, first of all agreed to define the style of the variable, for jquery object variable before adding $, such as:
var $variable =jquery object. If the DOM object, the Var Variable=dom object.
Use the [index] method and the Get (index) method to turn the JQuery object into a DOM object: Var $cr =$ ("#cr"),->var cr= $cr [0], or var cr= $cr. Get (0); Wrapping a DOM object in $ () becomes a jquery object.
Case Study (forum registration), Dom mode:
1 <!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd ">2 <HTML>3 <Head>4 <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" />5 <title>1-6-2</title>6 <!--Introducing JQuery -7 <Scriptsrc=".. /.. /scripts/jquery.js "type= "Text/javascript"></Script>8 <Scripttype= "Text/javascript">9 //wait for the DOM element to finish loading.Ten $ (document). Ready (function(){ One var$CR= $("#cr"); //jquery Object A varCR=$cr. Get (0); //Dom object, getting $CR [0] - $CR. Click (function(){ - if(cr.checked) {//Dom Way to judge the Alert ("Thank you for your support! You can continue!"); - } - }) - }); + </Script> - </Head> + <Body> A <inputtype= "checkbox"ID= "Cr"/> <label for= "Cr">I have read the above system.</label> at </Body> - </HTML>
jquery Method:
1 <!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd ">2 <HTML>3 <Head>4 <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" />5 <title>1-6-1</title>6 <!--Introducing JQuery -7 <Scriptsrc=".. /.. /scripts/jquery.js "type= "Text/javascript"></Script>8 <Scripttype= "Text/javascript">9 //wait for the DOM element to finish loading.Ten $ (document). Ready (function(){ One var$CR= $("#cr"); //jquery Object A $CR. Click (function(){ - if($CR. Is (": Checked")){ //The jquery way of judging, is (": Checked") is a method in jquery, to determine whether the jquery object is selected - Alert ("Thank you for your support! You can continue! "); the } - }) - }); - </Script> + </Head> - <Body> + <inputtype= "checkbox"ID= "Cr"/><label for= "Cr">I have read the above system.</label> A </Body> at </HTML>
"Sharp jquery" reading Essentials notes