1. JQuery Event:
////hover: Equivalent to the equivalent of MouseOver () mouseout ( ) //$ ("#div1"). Hover (function ()//{ //$ (this). CSS ("Background-color", "Red"); //}, //function ()// { //$ (this). CSS ("Background-color", "Blue"); // }); //Toggle: Click event Loop to execute//$ ("#div1"). Toggle (function ()//{ //$ (this). CSS ("Background-color", "Red"); //}, function ()//{ //$ (this). CSS ("Background-color", "Blue"); //}, function ()//{ //$ (this). CSS ("Background-color", "green"); //}, function ()//{ //$ (this). CSS ("Background-color", "Gray"); //}); //future elements of live usage://$ (". Div2"). Click (function () {//alert ("AA"); //});
$ (". Div2"). Live ("Click", Function () {
Alert ("AA");
});
//Block event bubbling://$ ("#div1"). Click (function ()//{ //alert ("111"); //return false; //}); //$ ("#div2"). Click (function () {//alert ("222"); //return false; //}); //$ ("#div3"). Click (function () {//alert ("333"); //return false; //}); //$ ("#div4"). Click (function () {//alert ("444"); //return false; //});
2. Dom Operation:
//Action Properties:$("#div1"). Click (function () {if($("#btn1"). attr ('Disabled') =='Disabled') { $("#btn1"). Removeattr ('Disabled'); } Else{ $("#btn1"). attr ('Disabled','Disabled');} });
//to manipulate the style sheet's class:$("#div1"). Click (function () {if($("#btn1"). attr ('class'). IndexOf ('B2') == -1) { $("#btn1"). AddClass ("B2"); } Else { $("#btn1"). Removeclass ("B2"); } $("#btn1"). Toggleclass ('B2'); });
$ ("#div4"). Click (function () { alert (this). Parent (). Parent (). attr ('ID')); }); $ ("#div4"). Click (function () { alert (this). Parent (). attr ('ID')); });
$("#btn1"). Click (function () {//NEW: varD1 = document.createelement ('Div'); D1.setattribute ("class","Div2"); $("#div1"). Append (D1); NEW: $ ("HTML String") $("#div1"). Append ($ ("<div class= ' div2 ' ></div>")); }); //Copy:$("#btn1"). Click (function () {varA = $ (". Div2:eq (1)"). Clone (); $("#div1"). append (a); });
2017-6-3 JQuery Event Dom operation