<!DOCTYPE html>
<html lang="en">
<head>
<Meta charset="UTF-8">
<title>事件</title>
<style>
p{
width:100px;
height:100px;
border: 1px solid gray;
}
</style>
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script>
$(function(){
/*
$('p').click(function(){
alert($(this).text());
});
*/
$('p').on({'click':function(e){
//alert(e); //$(this).text()
console.log(e)
},
'mouSEOver':function(){$(this).css('background','blue');},
'mouSEOut':function(){$(this).css('background','white')}});
//事件的委派
$('div').delegate('button','click',function(){
$(this).prev().slidetoggle();
})
});
</script>
</head>
<body>
<p>AAAA</p>
<p>BBBB</p>
<p>CCCC</p>
<div style="background-color:red">
<p>这是一个段落。</p>
<button>请点击这里</button>
</div>
</body>
</html>