Event binding Short Form $ (". Div2 button"). Click (function () { $ (". Div1"). ScrollTop (0) }) //write all the way $ ('. Div2 Button '). Bind (' click ', Function () { }) //Unbind $ ('. Div2 button '). Unbind (' click ', Function () { })
The event delegate takes note of the order of three parameters, the first one is the binding event, the second is the label, and the third is the method/ * $ (' ul '). On (' Click ', ' Li ', function () { alert (999) }); $ (' button '). Click (function () { var $ele =$ (' <li></li> '); var len=$ (' ul li '). length; Console.log (333) $ele. HTML ((len+1) +111); $ (' ul '). Append ($ele); })
The page loads the first method of $ (document). Ready (function () {//etc after the entire document executes, the code is executed in $ (' ul Li '). HTML (5); }); Page loading the second method $ (function () { });
jquery Event binding and event delegation