2013-12-18 83 views
0

I have a div which is clickable (it is a collapse) and a link on top of it:如何設置的link_to(只是一個普通的<a href>) to be clickable through a clickable div?

<div class="panel-group" id="accordion"> 
    <div class="panel panel-default"> 
     <div class="panel-heading"> 
      <h4 class="panel-title"> 
       <a data-parent="#accordion" data-toggle="collapse" href="#w_abcd" class="collapsed"> 
       <table class="table-condensed w"> 
        <tbody> 
         <tr> 
          <td class="col-sm-2">abcd</td> 
          <td class="col-sm-2">aaa</td> 
          <td class="col-sm-2">bbb</td> 
          <td class="col-sm-2"> 
           <a href="/ws/52b0f6a676646503c9000000">Show</a> 
          </td> 
          <td class="col-sm-2"> 
           <a href="/ws/52b0f6a676646503c9000000/edit">Edit</a> 
          </td> 
          <td class="col-sm-2"> 
           <a data-confirm="Are you sure?" data-method="delete" href="/ws/52b0f6a676646503c9000000" rel="nofollow">Destroy</a> 
          </td> 
         </tr> 
        </tbody> 
       </table> 
       </a> 
      </h4> 

     </div> 
     <div class="panel-collapse collapse" id="w_abcd" style="height: 0px;"> 
      <div class="panel-body">aaa</div> 
      <ul class="list-group"> 
       <li class="list-group-item">bbb</li> 
      </ul> 
     </div> 
    </div> 
    <div class="panel panel-default"> 
     <div class="panel-heading"> 
      <h4 class="panel-title"><a data-parent="#accordion" data-toggle="collapse" href="#w_1234" class="collapsed"><table class="table-condensed w"><tbody><tr><td class="col-sm-2">1234</td><td class="col-sm-2">abcd</td><td class="col-sm-2">12311</td><td class="col-sm-2"><a href="/ws/52b0f83076646503c9010000">Show</a></td><td class="col-sm-2"><a href="/ws/52b0f83076646503c9010000/edit">Edit</a></td><td class="col-sm-2"><a data-confirm="Are you sure?" data-method="delete" href="/ws/52b0f83076646503c9010000" rel="nofollow">Destroy</a></td></tr></tbody></table></a></h4> 

     </div> 
     <div class="panel-collapse collapse" id="w_1234" style="height: 0px;"> 
      <div class="panel-body">abcd</div> 
      <ul class="list-group"> 
       <li class="list-group-item">12311</li> 
      </ul> 
     </div> 
    </div> 
</div> 

http://jsfiddle.net/6cA6L/

如何在點擊鏈接的時候?那麼如何點擊thwough可點擊DIV執行鏈接下面,而不是UI JS(崩潰)?

回答

1
$('tr a').click(function(e){ 
    e.stopPropagation(); 
}); 

當u點擊鏈接,該事件被傳播到父,首先你需要停止事件冒泡父

updated fiddle

+0

這就是現在的工作,但有一個問題:如果我點擊鏈接('展','編輯')a因此,進入「顯示」或「編輯」頁面,然後在瀏覽器中單擊,e.stopPropagation()技巧就不再起作用。可能是什麼問題呢?我把'e.stopPropagation()'放在 – static

+0

裏的'$(document).ready(function(){...})'裏面,它正在工作,檢查一次,可能還有其他的js正在處理它 – Bhadra