the basis of jQuery Event Processing

jQuery basis of event processing method, as shown below:

 

 Code:

. 1   < Script the src = "the JS / jQuery-1.12.4.min.js" > </ Script > 
2      < Script > 
. 3          // a first embodiment of the event broker 
4          // event bubbling, the event is passed subtag to a parent tag 
5          // will click when the click event is transmitted to the parent sub-tab label, leading to the parent tag click event is also performed 
. 6          $ ( function () {
 . 7              var $ DIV1 = $ ( ' # DIV1 ' );
 . 8              div1.click $ ( function () {
 . 9                  Alert ( ' parent tag '  + $ div1.html ())
10              });
 . 11              var $ Div2 = $ ( ' # Div2 ' );
 12 is              $ div2.click ( function () {
 13 is                  Alert ( ' subtag '  + $ div2.html ())
 14              });
 15          });
 16          // second embodiment of the event broker 
17          @ using methods completion event delegate agent 
18 is          
. 19          $ ( function () {
 20 is              // get the parent label object 
21 is              $ DIV3 = $ ( 'DIV3 # ' );
 22 is              $ div3.delegate ( ' P ' , ' the Click ' , function () {
 23 is                  // the this element which is a child tag objects 
24                  $ ( the this ) .css ({
 25                      Color: ' Red ' ,
 26 is                      width: ' 300px by ' ,
 27                      height: ' 200px ' ,
 28                      background: ' Yellow '
29                 });
30             });
31         });
32     </script>
33 
34 
35 <body>
36     <div id="div1">111
37         <div id="div2">22</div>
38     </div>
39     <div>
40         <div id="div3">
41             <p>Use delegate method to complete the event broker</p>
42         </div>
43     </div>
44 </body>

 

Guess you like

Origin www.cnblogs.com/chao666/p/12018423.html