1 delegate()函数的作用
delegate() 方法为指定的元素(属于被选元素的子元素)添加一个或多个事件处理方法;
示例:
<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("div").delegate("#bnt1","click",function(){
$("p").hide();
});
$("div").delegate("#bnt2","click",function(){
$("p").show();
});
});
</script>
</head>
<body>
<div style="background-color:red">
<p>这是一个段落。</p>
<button id="bnt1">隐藏段落</button>
<button id="bnt2">显示段落</button>
</div>
</body>
</html>