1.事件委托的基本结构
$(function(){
$("button").click(function(){
$("ul").append("<li>我是新增的li</li>");
});
$("ul").delegate("li","click",function(){
console.log($(this).html());
});
});
2.事件委托的练习一(弹框)
$(function(){
$('a').click(function(){
var $mask = $("<div class=\"mask\">\n"+
" <div class=\"login\">\n"+
"<img src=\"https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=2928342431,2801225001&fm=173&app=25&f=JPEG?w=218&h=146&s=4680DAAA4C927CD05A8607A703009005\" />\n"+
"<span></span>\n" +
"</div>\n" +
"</div>");
$("body").append($mask);
$("body").delegate(".login>span","click",function(){
$mask.remove();
});
return false;
});
});