如何停止传播并同时允许模态?

时间:2018-06-26 11:59:12

标签: javascript jquery twitter-bootstrap events bootstrap-modal

我在表格行(<tr>中有两个按钮。每当单击按钮时,我都有以下事件处理程序,以防止该行也接收到该单击。

$(".btn").on('click', function(e){
    e.stopPropagation();
})

这也可以防止模态打开。

我有以下按钮:

<tr> 
    <td>
        <a><button data-toggle="modal" data-target= "#emailModal" data-player="<%=JSON.stringify(player)%>" data-player_id="<%=doc.id%>" data-result="pass" data-recipient="<%=player.email%>" class="btn btn-outline-danger action-btn reject-btn">Reject</button></a>
        <a><button data-toggle="modal" data-target= "#emailModal" data-player="<%=JSON.stringify(player)%>" data-player_id="<%=doc.id%>" data-result="Approve" data-recipient="<%=player.email%>" class="btn btn-outline-success action-btn approve-btn">Approve</button></a>
    </td>
</tr>

如何确保事件传播到模式,以便启动/显示但不传播到外部div(<tr>)?

编辑

<% players.forEach(doc => { %>
     <tr class="trow" onclick="document.location = '/leaderboard/<%=doc.id%>';">

1 个答案:

答案 0 :(得分:0)

使用type="button"和这个

<% players.forEach(doc => { %>
 <tr class="trow" data-location="/leaderboard/<%=doc.id%>">

使用

$("tr[data-location]").on("click",function(e)  { 
  if (!$(e.target).is(".btn")) {
    location = $(this).attr("data-location");
  }
})
相关问题