Php 单击复选框时隐藏表行
我有这个表,使用这个php代码获取行,当我点击这个复选框时,会显示一条警报消息,如果用户点击该警报的ok按钮,那么我想隐藏相应的行Php 单击复选框时隐藏表行,php,javascript,jquery,html,css,Php,Javascript,Jquery,Html,Css,我有这个表,使用这个php代码获取行,当我点击这个复选框时,会显示一条警报消息,如果用户点击该警报的ok按钮,那么我想隐藏相应的行 <table> <tr> <th style="height: 25px">NAME</th> <th style="height: 25px">EMAIL</th> <th style="height: 25px">CELL
<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
调用函数,传入checkbox元素。在函数中,可以隐藏其父元素
(行)元素
使用此代码
<!DOCTYPE html>
<html>
<head>
<script>
function hiderow(check)
{
if(confirm('This action can not be recovered, are you sure you want to HIDE this Candidate? '))
{
check.parentNode.parentNode.style.display = "none";
return true;
}
return false;
}
</script>
</head>
<body>
<table id="myTable" border="1">
<tr>
<td>cell 1</td>
<td>cell 2</td>
<td> <input type="checkbox" name="row_2" onclick="return hiderow(this)" /> </td>
</tr>
<tr>
<td>cell 3</td>
<td>cell 4</td>
<td> <input type="checkbox" name="row_2" onclick="return hiderow(this)" /> </td>
</tr>
</table>
<br>
<button type="button" onclick="displayResult()">Delete first row in the table</button>
</body>
</html>
函数hiderow(检查)
{
如果(确认('此操作无法恢复,是否确实要隐藏此候选对象?'))
{
check.parentNode.parentNode.style.display=“无”;
返回true;
}
返回false;
}
第1单元
第2单元
第三单元
第4单元
删除表中的第一行
您应该修改输入字段,如下所示:
<input type="checkbox" name="hide_cand" id="hide_cand" onclick="return confirmation(this); return false;"/>
然后将此脚本添加到您的页面,它应该可以工作:)
。它们不再得到维护。看到了吗?相反,学习,并使用or-将帮助您决定哪一个。如果你选择PDO,.@ RAJ,如果这解决了问题,考虑接受答案:)使用这个行是隐藏的,但只是暂时的,如何永久地隐藏它。@ RAJ,如果你需要坚持它到一个数据源,那么它可能会更好地作为一个新的问题与具体的细节(如DB系统等)。我已经解决了我的查询,谢谢你的回答,但我不知道如何在代码中插入它。
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;
}
<!DOCTYPE html>
<html>
<head>
<script>
function hiderow(check)
{
if(confirm('This action can not be recovered, are you sure you want to HIDE this Candidate? '))
{
check.parentNode.parentNode.style.display = "none";
return true;
}
return false;
}
</script>
</head>
<body>
<table id="myTable" border="1">
<tr>
<td>cell 1</td>
<td>cell 2</td>
<td> <input type="checkbox" name="row_2" onclick="return hiderow(this)" /> </td>
</tr>
<tr>
<td>cell 3</td>
<td>cell 4</td>
<td> <input type="checkbox" name="row_2" onclick="return hiderow(this)" /> </td>
</tr>
</table>
<br>
<button type="button" onclick="displayResult()">Delete first row in the table</button>
</body>
</html>
<input type="checkbox" name="hide_cand" id="hide_cand" onclick="return confirmation(this); return false;"/>
<script type="text/javascript">
<!--
function confirmation(item) {
var answer = confirm("This action can not be recovered, are you sure you want to HIDE this Candidate?")
if (answer){
alert("confirmed yes!")
item.parent().parent().hide();
}
else{
alert("confirmed no!")
}
}
//-->
</script>