我有这个表,并使用这个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>";
}
?>
答案 0 :(得分:2)
从onclick
调用函数,传入checkbox元素。在函数中,您可以隐藏它的父<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;
}
答案 1 :(得分:0)
$('#your_chk_id').live('click', function(){
$(this).parent('tr').hide();
});
答案 2 :(得分:0)
使用此代码。
<!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>
答案 3 :(得分:0)
您应该像这样修改输入字段:
<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>