Php 在while循环中切换表的行

Php 在while循环中切换表的行,php,jquery,html,Php,Jquery,Html,我有一个带有几个按钮的表格,上面有显示文本。每次单击其中一个按钮时,我都希望显示带有class.infotr的行,当我再次单击相同的按钮时,这些行消失。我指的是单击按钮的同一个表中的.infotr行 <?php $sql="SELECT * FROM mytable WHERE ID='$id'"; $res=mysqli_query($db,$sql); while($row = mysqli_fetch_array($res)) { echo "<table id='

我有一个带有几个按钮的表格,上面有显示文本。每次单击其中一个按钮时,我都希望显示带有class.infotr的行,当我再次单击相同的按钮时,这些行消失。我指的是单击按钮的同一个表中的.infotr行

<?php 
$sql="SELECT * FROM mytable WHERE ID='$id'";
$res=mysqli_query($db,$sql);

while($row = mysqli_fetch_array($res))
{
    echo "<table id='tablemodificamobile'>";
    echo "<tr id='firsttr'>";
    echo "<td id='amid' class='modificatd'>".$myid."</td>";
    echo "<td id='amtitle' class='modificatd'>".$row['Title']."</td>";
    echo "<td id='amshow' class='modificatd'><input type='button' id='mostramodbtn' value='SHOW'></input></td>";
    echo "</tr>";
    echo "<tr class='infotr'><td class='addinfo'>New Price: ".$row['NewPrice']."</td></tr>";
    echo "<tr class='infotr'><td class='addinfo'>Old Price: ".$row['OldPrice']."</td></tr>";
    echo "<tr class='infotr'><td class='addinfo'><input type='button' value='SAVE' id='modit'></input></td></tr>";
    echo "</table>";
}
?>
使用以下命令:

$(document).on('click','#mostramodbtn',function() {
   $(this).parents("tr").nextAll().toggle("slow");
});
您正在动态创建元素,因此需要使用.on函数绑定偶数on文档


了解有关的详细信息。

您可以扩展到它不起作用吗?请使用“切换”而不是“显示”。出现class.infotr的行,当我再次单击相同的按钮时,这些行disappear@nada我同意你的看法。应该有使用。切换功能。谢谢。我使用了切换,但是我在测试中用show更改了它,并且忘记了在问题中将show更改为toggle。
$(document).on('click','#mostramodbtn',function() {
   $(this).parents("tr").nextAll().toggle("slow");
});