jQuery中的on 和事件委派

<!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>

 

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...