我有这张表,并使用此 php 代码获取行,当我单击此复选框时会显示一条警报消息,如果用户单击该警报的确定按钮,我想隐藏该特定行。
<table>
<tr>
<th style="height: 25px">NAME</th>
<th style="height: 25px">EMAIL</th>
<th style="height: 25px">CELL NO</th>
<th style="height: 25px">CITY</th>
<th>Hide Candidate</th>
</tr>
</table>
<?php
while($data_set1 = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>{$data_set1['ename']}</td>";
echo "<td>{$data_set1['eemail']}</td>";
echo "<td>{$data_set1['ecell']}</td>";
echo "<td>{$data_set1['ecity']}</td>";
echo "<td><input type=\"checkbox\" name=\"hide_cand\" id=\"hide_cand\" onclick=\"return confirm('This action can not be recovered, are you sure you want to HIDE this Candidate? ')\"/></td>";
echo "</tr>";
}
?>
最佳答案
从 onclick
调用函数相反,传入复选框元素。在函数中,你可以隐藏它的父级 <tr>
(行)元素。
echo "<td><input type=\"checkbox\" name=\"hide_cand\" id=\"hide_cand\" onclick=\" return hideRow(this)\"/></td>";
Javascript:
function hideRow(checkbox)
{
if(confirm('This action can not be recovered, are you sure you want to HIDE this Candidate? '))
{
checkbox.parentNode.parentNode.style.display = "none";
return true;
}
return false;
}
关于php - 选中复选框时隐藏表格行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13988936/