HTML 练习on方法
程序员文章站
2022-05-04 14:13:22
on方法,传递参数 ......
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>title</title> <script src="jquery-3.3.1.min.js"></script> </head> <body> <ul> <li>111</li> <li>222</li> <li>333</li> <li>444</li> </ul> <input type="button" value="+" onclick="add()"> <script> $("ul").on("click", "li", function(){ alert(888) }) function add(){ $("ul").append("<li>555</li>") } </script> </body> </html>
on方法,传递参数
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>title</title> <script src="jquery-3.3.1.min.js"></script> </head> <body> <p>hello p</p> </body> <script> function myhandler(e){ alert(e.data.foo) } $("p").on("click", {foo: "klvchen"}, myhandler) </script> </html>