php - 选中复选框时隐藏表格行

标签 php javascript jquery html css

我有这张表,并使用此 php 代码获取行,当我单击此复选框时会显示一条警报消息,如果用户单击该警报的确定按钮,我想隐藏该特定行。 check box is shown in image

<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/

相关文章:

javascript - 使用 Javascript 创建帐户

php - 如何从管理区域动态更改图像?

php - 除非删除 PHP 代码,否则不会显示登录页面

javascript - 如何检测 "copy image"浏览器事件?

jquery 中的 javascript 切换未按预期工作

javascript - bool 玛卡的简单 jQuery 切换不起作用

javascript - Ajax 不会从 php 文件中检索文件

javascript - Node.js 同步循环或迭代异步语句

javascript - 使用 Javascript 更改网站语言

jquery - 根据jquery中的选项值从选择中删除了选项