jquery live()和$this

jquery live()和$this,jquery,Jquery,我在jQuery的live上遇到了问题。单击同一容器div的divcomment时,divone应向下滑动。发生的情况是,每个divone都在向下滑动,而不管它们的容器是什么。我该如何解决这个问题?我认为这是$this函数,但我不知道如何实现它 <script type="text/javascript"> $('.one').hide(); $('.comment').live('click',function() { if ($('.one').is(

我在jQuery的live上遇到了问题。单击同一容器div的div
comment
时,div
one
应向下滑动。发生的情况是,每个div
one
都在向下滑动,而不管它们的容器是什么。我该如何解决这个问题?我认为这是$this函数,但我不知道如何实现它

<script type="text/javascript">
  $('.one').hide();      
  $('.comment').live('click',function() {
    if ($('.one').is(':hidden')) {
      $('.one').slideDown('slow');
    }
  });
</script>

<?php
  for($i=0;$i<11;$i++) {
?>
<div class='container'>
  <a class='comment'>comment</a>
    <div class='one'>
      <textarea style='width:350px;height:100px'>Type text here</textarea>
    </div>
  </div>
<?php
  }
?>

$('.one').hide();
$('.comment').live('click',function()){
如果($('.one')。是(':hidden')){
$('.one')。向下滑动('slideDown');
}
});
评论
在此处键入文本
在这种情况下(从提供的信息中)
不需要使用live()
,您只需使用
。单击()

函数的主体可以如下所示

$one = $(this).next('.one'); //select the specific .one div you want
if ($one.is(':hidden')) {
    $one.slideDown('slow');
} 
您希望只针对特定的
。要显示的一个
div。。。当前您的目标是每个
.one
分区。

在这种情况下(从提供的信息中)
。不需要live()
,您只需使用
。单击()

函数的主体可以如下所示

$one = $(this).next('.one'); //select the specific .one div you want
if ($one.is(':hidden')) {
    $one.slideDown('slow');
} 
您希望只针对特定的
。要显示的一个
div。。。您当前的目标是每个
。一个
分区。

尝试:

  $('.comment').live('click',function() {
      $(this).siblings('.one').slideDown('slow');
  });
尝试:


$('.one').hide();
$('.comment').live('click',function()){
var sameone=$(this.next('.one');
if(sameone.is(':hidden')){
sameone.slideDown('slow');
} 
});

$('.one').hide();
$('.comment').live('click',function()){
var sameone=$(this.next('.one');
if(sameone.is(':hidden')){
sameone.slideDown('slow');
} 
});
只需使用
next()

只需使用
next()

$('.one')
选择类为
one
的每个元素,这是预期的。
$('.one')
选择类为
one
的每个元素,这是预期的。
 $('.one').hide();       
    $('.comment').live('click',function() {
       if ($(this).next('.one').is(':hidden')) {
          $(this).next('.one').slideDown('slow');
       }
 });