代码之家  ›  专栏  ›  技术社区  ›  rgoncalv

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

  •  0
  • rgoncalv  · 技术社区  · 8 年前

    我在一排桌子上有两个按钮( <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 回复  |  直到 8 年前
        1
  •  0
  •   mplungjan    8 年前

    使用 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");
      }
    })