jQuery中的事件委托
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<script src="jquery-1.10.1.min.js"></script>
<script>
$(function(){
/*$('li').on('click',function(){
this.style.background = 'red';
});*/
$('ul').delegate('li','click',function(){ // 事件委托
this.style.background = 'red';
$('ul').undelegate(); // 阻止事件委托
});
});
</script>
</head>
<body>
<ul>
<li>11111</li>
<li>1111</li>
<li>1111</li>
<li>111</li>
<li>1111</li>
</ul>
</body>
</html>
author:Lik
Endeavoring to powerless, struggling to move yourself.
Endeavoring to powerless, struggling to move yourself.