on(type,[data],fn)
on有三个参数,type代表事件类型,可以为“click"、"onchange"、"mouseover"
data可以不传,如果传入data,可以在fn中以e.data取到
fn:函数,形参传入e,e.target可以拿到当前被点击的元素
delegate(selector,type,[data],fn)
selector:选择器
on(type,selector,[data],fn)
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>test2</title> </head> <body> <ul id="ul" style="padding:20px"> <li>1</li> <li>2</li> <li>3</li> <li>4</li> </ul> <input type="button" value="add" id='add'> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script type="text/javascript"> $(function(){ // $("#ul").bind("click",{name:"Annie"},function(e){ // console.log(e.target); // console.log(e.data); // }) $("#ul").delegate("li","click",{name:"Annie"},function(e){ console.log(e.target); console.log(e.data); }) // $("#ul").on("click","li",{name:"Annie"},function(e){ // console.log(e.target); // console.log(e.currentTarget); // console.log(e.data); // }) $("#add").click(function(){ console.log('add'); $("#ul").append("<li>5</li><li>6</li><li>7</li>"); }) }) </script> </body> </html>