jquery $(this)

来源:互联网 发布:知乎活跃用户数量 编辑:程序博客网 时间:2024/06/01 10:22

this表示的是当前对象,下面以例子来说明

[javascript] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4. <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">  
  5. </script>  
  6. <script>  
  7. $(document).ready(function(){  
  8.   $("p").click(function(){  
  9.     $(this).hide();//$(this)是在方法click内,此处的$(this)表示的是当前调用click方法的对象$("p"),就是表示当前对象,当前调用该方法的对象  
  10.   });  
  11. });  
  12. </script>  
  13. </head>  
  14. <body>  
  15. <p>如果您点击我,我会消失。</p>  
  16. <p>点击我,我会消失。</p>  
  17. <p>也要点击我哦。</p>  
  18. </body>  
  19. </html>  

原创粉丝点击