1

我有这个声明

<div class="divShow">
   <ul id="ulShow">           
     <li>
       <h3 class="CompanyShow">A</h3>
       <h2 class="ShowTitle">S</h2>                
       <input class="ExpShow" type="button" value="Edit">           
     </li>
     <li>
       <h3 class="CompanyShow">A2</h3>
       <h2 class="ShowTitle">T1</h2>
       <input class="ExpShow" type="button" value="Edit">
      <li>
    </ul>
</div>

当我单击"Edit"按钮时,我必须显示相应的数据。

当我单击"Edit"第一个列表的按钮时,它应该显示A,如果我单击第二个li,它应该显示A2

如何使用 jQuery 做到这一点?

 $('.EditExp').live('click',function(){
     $('.divShow ul li').each(function(){
         alert($(this).parent().find('h3.CompanyShow').html());                 
     });                 
 });
4

2 回答 2

1

这应该适合你。这里的想法是我在所有按钮上放置一个点击处理程序,然后我选择.CompanyShow仅与按钮相关的元素。

演示

$('.ExpShow').on('click', function(){
    var $this = $(this);
    alert(  $this.prevAll('.CompanyShow').text());     
}); // end on click 
于 2013-05-05T05:36:16.377 回答
0
$('.ExpShow').click( function() {
  var html = $(this).closest('li').find('.CompanyShow').html();
  alert( html );
});
于 2013-05-05T05:41:30.473 回答