如何设置link_to(只是普通<a href="">) to be clickable through a clickable div?</a>

时间:2013-12-18 10:21:32

标签: javascript jquery html hyperlink

我有一个可点击的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/

如何在点击链接时执行以下链接而不是UI js(折叠)?那么如何点击可点击的div?

1 个答案:

答案 0 :(得分:1)

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

当你点击链接时,事件会传播到父级,首先你需要停止冒充父级的事件

updated fiddle