日期:2014-05-16  浏览次数:20404 次

请教jquery使用


<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $(".ex .hide").click(function(){
    alert(this.parents);
    $(this).parents(".ex").hide();
  });
});
</script>
<style type="text/css"> 
div.ex
{
background-color:#e5eecc;
padding:7px;
border:solid 1px #c3c3c3;
}
</style>
</head>
 
<body>

<h3>text a</h3>
<div class="ex">
<button class="hide" type="button">隐藏</button>
<p>联系人:张先生<br /> 
北三环中路 100 号<br />
北京</p>
</div>

<h3>text b</h3>
<div class="ex">
<button class="hide" type="button">隐藏</button>
<p>联系人:David<br /> 
第五大街 200 号<br />
纽约</p>
</div>

</body>
</html>




请教这段代码中 我加上alert(this.parents); 想查看this.parents 弹窗显示未定义 这个应该怎么理解 
------解决方案--------------------
JQUERY对象 有parents方法,而不是属性,Html页面元素对象有parentNode属性,得到父级

$(document).ready(function(){
  $(".ex .hide").click(function(){
    alert($(this).parents());
alert(this.parentNode);
    $(this).parents(".ex").hide();
  });
});