2016-08-17 52 views
-2

我想在使用jQuery的时候在html表格的末尾添加一列。如何使用jQuery在html表格末尾添加列?

我创建了以下HTML表格。

<table class="table table-bordered table-striped" id="reportColumns"> 

    <thead> 
     <tr></tr> 
    </thead> 

    <tbody> 
     <tr></tr> 
    </tbody> 

</table> 

然后我说下面的jQuery代码

$('.checkbox').click(function(){ 
     var id = $(this).attr('data-tag'); 

     $("#reportColumns > thead > tr").append('<th id="'+ id +'">Some Column header</th>'); 

     $("#reportColumns > tbody > tr").append('<td>-</td>'); 
}); 

但出于某种原因,这是行不通的。没有列被添加到表中。甚至没有可见的表格。

我该如何解决这个问题?

+0

有了这个分数,这些徽章,你不能让一个最小的努力来正确地格式化你的问题?或者发布一个MCVE? – Amit

+0

您确定.checkbox侦听器正在被解雇吗? – Sergeon

+0

@Sergeon是的。我甚至登录到控制台 – Jaylen

回答

1

入住这jsfiddle

<table class="table table-bordered table-striped"  id="reportColumns"> 

     <thead> 
      <tr>fasdfsa</tr> 
     </thead> 

     <tbody> 
      <tr>afsdfa</tr> 
     </tbody> 

    </table> 
    <div class="checkbox">Click me</div> 
相关问题