JQuery -- this 和 $(this) 的区别

来源:互联网 发布:关于淘宝店铺转让 编辑:程序博客网 时间:2024/05/21 22:25
<script type="text/javascript">  $(document).ready(function(){      $("div").each(function(){          alert($(this).html() + "----" + this.tagName + "--" + $(this)[0].id);          alert((this == $(this)[0]));          $(this).attr("title", $(this).html());      });  });  </script>  </head>  <body>  <div id="node1">sss1</div>  <div id="node2">sss2</div>  </body>  
#这里的this其实是一个Html元素(div),获取html属性值均可用this.属性名来取值
#这里的$(this)是一个JQuery对象,可以调用JQuery的方法
# this == $(this)[0] 返回为true
#JQuery拥有attr()方法可以get/set DOM对象的属性

原创粉丝点击