【问题标题】:How detect which delete button was clicked?如何检测单击了哪个删除按钮?
【发布时间】:2015-11-17 00:11:32
【问题描述】:

我在我的网站上使用 Semantic-UI。我有数据表,每一行都是删除按钮。单击按钮时,将显示模态。模态有两个按钮,取消或确认。当我单击确认时,我想从数据库中删除行。但是我如何检测点击了哪个按钮?

HTML 表格:

<tr>
   <td>Name</td>
   <td>      
      <button id='1' class="delete button"></button>
   </td>
</tr>
<tr>
   <td>Name2</td>
   <td>      
      <button id='2' class="delete button"></button>
   </td>
</tr>

当我点击表格中的删除按钮时,会显示 javascript 模式。 MODAL Javascript

$('#removeAcredicationModal')
                .modal({
                    transition       : 'vertical flip',
                    mobileTransition : 'horizontal flip',
                    closable         : false,
                    approve          : '.submit, .approve',
                    deny             : '.cancel'
                    }
                })
                .modal('attach events', '.delete', 'show')
            ;

模态 HTML

<div id="removeAcredicationModal" class="ui small modal">
   <div class="ui approve submit green labeled icon button">
      <i class="checkmark icon"></i>
      Delete
   </div>
   <div class="ui cancel red labeled icon button">
      <i class="remove icon"></i>
      Cancel
   </div>
</div>

在确认按钮上单击我想从数据库中删除项目

function doDelete(){
    var idOfRowToDelete = "??";
    //How to get the ID placed in table?
    //Using controller, etc...
};

知道如何在 toDelete 函数中从表中获取 ID 吗?

【问题讨论】:

    标签: javascript jquery html semantic-ui


    【解决方案1】:

    使用e.target.id

    $('button').click(function(e)
    {
        alert(e.target.id);
       e.preventDefault(); 
    });
    

    http://jsfiddle.net/38h1ub4j/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-09
      • 1970-01-01
      • 1970-01-01
      • 2012-03-15
      • 2017-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多