繁体   English   中英

无法从表格行上的按钮获取引导按钮ID

[英]Can't get bootstrap button ID from button on a table row

我使用的是Bootstrap,以为自己会很聪明,然后在表中放一些按钮。 las,什么都没有发生。 按钮状态发生变化,但除此之外,没有错误,没有警报,没有任何响应。

我的缩写表

<table class="table">
    <tr>
        <td>Entry of some sort</td>
        <td><button type="button" class="btn btn-default btn-xs" id="edit_Button">Edit</button></td>
        <td><button type="button" class="btn btn-default btn-xs" id="delete_Button">Delete</button></td>
    </tr>
</table>

jQuery为我的按钮

$( document ).ready(function() {    
    $(".table .btn").click(function(e){
        e.preventDefault();
        var id = $(this).attr('id');
        alert(id);
    });
});

$(document).ready(function ()定义函数

由于您的按钮是根据DOM动态创建的,因此click事件将不适用于这些按钮。 在这种情况下,事件委托将帮助您附加该事件。

尝试这个

$(document).ready(function () {
    $(document).on('click', ".table .btn", function (e) {
        e.preventDefault();
        id = $(this).attr('id')
        alert(id);
    });
});

DEMO

请在Dom Ready添加您的功能

尝试这个

    $(function(){

        $('body').on('click','.table .btn','',function(e){
          e.preventDefault();
          var id = $(this).attr('id');
          alert(id);
         });

     });

在此处检查演示

写你的jQuery

$(document).ready(function(){
 //here
      $(".table .btn").click(function(e){
      e.preventDefault();
      id = $(this).attr('id')
      alert(id);
      });
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM