jQuery中的on 和事件委派
生活随笔
收集整理的這篇文章主要介紹了
jQuery中的on 和事件委派
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
<!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>請點(diǎn)擊這里</button>
</div>
</body>
</html>
?
總結(jié)
以上是生活随笔為你收集整理的jQuery中的on 和事件委派的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【Django】数据库主从配置
- 下一篇: 离线地图下载和发布