您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
一、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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。