Php 单击按钮时删除表行不能使用jquery

Php 单击按钮时删除表行不能使用jquery,php,jquery,html,Php,Jquery,Html,单击按钮时出现问题表行未被删除tr id和按钮id都是相同的值。请告诉我哪里做错了 <tr id="<?php echo $result->id;?>"> <td><input type="text" name="feature[]" class="text-input medium-input datepickur" value="<?php echo $result->feature;?>" /></td&g

单击按钮时出现问题表行未被删除tr id按钮id都是相同的值。请告诉我哪里做错了

<tr id="<?php echo $result->id;?>">

  <td><input type="text" name="feature[]" class="text-input medium-input datepickur" value="<?php echo $result->feature;?>" /></td>

  <td><button type="button" name="remove" id="<?php echo $result->id;?>" class="btn btn-danger button_remove">X</button></td>

</tr>

提前感谢
id
如果要在
jQuery
中使用它们,则每个元素都必须是唯一的,并且您的代码不起作用(因为
tr
td
id
共享相同的值)

简化您的代码


注意:-从
tr
td
中删除
id
。因为它根本不需要。它将使您的
HTML
结构正确且更清晰。

id
如果要在
jQuery
中使用它们,并且您的代码不起作用,则每个元素都需要唯一(
tr
td
id
共享相同的值)

简化您的代码


注意:-从
tr
td
中删除
id
。因为它根本不需要。它将使您的
HTML
结构正确且更清晰。

这是因为您对
tr
按钮使用相同的id
…尝试在此处使用
数据属性

<tr id="<?php echo $result->id;?>">
  <td><input type="text" name="feature[]" class="text-input medium-input datepickur" value="<?php echo $result->feature;?>" /></td>
  <td><button type="button" name="remove" data-row="<?php echo $result->id;?>" class="btn btn-danger button_remove">X</button></td>
<tr>

这是因为您对
tr
按钮使用相同的id
…请尝试在此处使用
数据属性

<tr id="<?php echo $result->id;?>">
  <td><input type="text" name="feature[]" class="text-input medium-input datepickur" value="<?php echo $result->feature;?>" /></td>
  <td><button type="button" name="remove" data-row="<?php echo $result->id;?>" class="btn btn-danger button_remove">X</button></td>
<tr>
$(文档).ready(函数(){
$('.button_remove')。单击(函数(){
$(this.parents().eq(1).remove();
});
});

X
X
$(文档).ready(函数(){
$('.button_remove')。单击(函数(){
$(this.parents().eq(1).remove();
});
});

X
X

tr id和按钮id相同表示违反规则不执行此操作。tr id和按钮id相同表示违反规则不执行此操作。@Arslan很高兴帮助您:):)。干杯:):)是的,5分钟后我就知道了it@Arslan很高兴帮助你:):)。谢谢你的评论谢谢你的评论谢谢你的评论你的评论你的代码是正确的,但实际上不需要这么多。只有
.closest()
可以在一行中完成工作,而不需要任何
id
数据属性
。您可以查看我的答案谢谢您的评论您的代码是正确的,但实际上不需要这么多。只有
.closest()
将在一行中完成此项工作,而没有任何
id
数据属性
。您可以查看我的答案
<tr id="<?php echo $result->id;?>">
  <td><input type="text" name="feature[]" class="text-input medium-input datepickur" value="<?php echo $result->feature;?>" /></td>
  <td><button type="button" name="remove" data-row="<?php echo $result->id;?>" class="btn btn-danger button_remove">X</button></td>
<tr>
$(document).ready(function() {
  $('.button_remove').click(function() {
    var btn_id = $(this).data("row");
    $('#' + btn_id + '').remove();
  });
});