您好,登錄后才能下訂單哦!
一、jQuery選擇器
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script src="jquery-1.10.1.min.js"></script> <script src="Selector.js"></script> </head> <body> <p>p1</p> <p class="pclass">p2</p> <button>Click me</button> </body> </html> $(document).ready(function(){ $("button").click(function(){ $(".pclass").text("p元素被修改了"); }) });
二、jQuery事件
1.jQuery事件:
常用事件方法
綁定事件
解除綁定事件
事件的目標(biāo)
事件的冒泡
自定義事件
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script src="jquery-1.10.1.min.js"></script> <script src="EventMethod.js"></script> </head> <body> <button>Click me</button> </body> </html> $(document).ready(function(){ // $("button").click(function(){ // $("button").dblclick(function(){ // $("button").mouseenter(function(){ $("button").mouseleave(function(){ $(this).hide(); }); });
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script src="jquery-1.10.1.min.js"></script> <script src="bindEvent.js"></script> </head> <body> <button id="clickMeBtn">Click me</button> </body> </html> $(document).ready(function(){ // $("#clickMeBtn").click(function(){ // alert("hello"); // }); // $("#clickMeBtn").bind("click",clickHandler1); // $("#clickMeBtn").bind("click",clickHandler2); // $("#clickMeBtn").unbind("click",clickHandler1); $("#clickMeBtn").on("click",clickHandler1); $("#clickMeBtn").on("click",clickHandler2); $("#clickMeBtn").off("click",clickHandler1); }); function clickHandler1(e){ console.log("clickHandler1"); } function clickHandler2(e){ console.log("clickHandler2"); }
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script src="jquery-1.10.1.min.js"></script> <script src="EventTarget.js"></script> </head> <body> <div > <li>A</li> <li>B</li> <li>C</li> <li>D</li> </div> </body> </html> $(document).ready(function(){ $("body").bind("click",bodyHandler); $("div").bind("click",divHandler1); $("div").bind("click",divHandler2); }); function bodyHandler(event){ console.log(event); } function divHandler1(event){ console.log(event); // event.stopPropagation(); event.stopImmediatePropagation(); } function divHandler2(event){ console.log(event); }
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script src="jquery-1.10.1.min.js"></script> <script src="CustomEvent.js"></script> </head> <body> <button id="ClickMeBtn">Click Me</button> </body> </html> var ClickMeBtn; $(document).ready(function(){ ClickMeBtn = $("#ClickMeBtn"); ClickMeBtn.click(function(){ var e = jQuery.Event("MyEvent"); ClickMeBtn.trigger(e); }); ClickMeBtn.bind("MyEvent",function(event){ console.log(event); }); });
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。