0

我有这个表,并使用这个 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>";
}
?>
4

4 回答 4

2

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;
}
于 2012-12-21T11:07:58.207 回答
0
$('#your_chk_id').live('click', function(){
  $(this).parent('tr').hide();
});
于 2012-12-21T11:07:48.393 回答
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>
于 2012-12-21T11:18:04.813 回答
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>
于 2012-12-21T11:18:56.833 回答