您好,登錄后才能下訂單哦!
一、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事件:
常用事件方法
綁定事件
解除綁定事件
事件的目標
事件的冒泡
自定義事件
<!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); }); });
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。