2012-12-24 76 views
0

我使用这个代码,以显示表隐藏行永久表

<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 hideRow(this)\"/></td>"; 
\"/></td>"; 
     echo "</tr>"; 
    } 
    ?> 

,并使用该JavaScript我可以暂时隐藏表中的行,如何permanantly隐藏它,当正装表

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; 
} 
+3

你总是可以......在'while()'循环中不输出'​​'?也许在行上设置一个'style =“display:none”'?你有没有想过这个? – Bojangles

+0

它实际上可以被恢复,因为我可以通过开发人员工具或萤火虫编辑HTML元素 –

+0

我想隐藏行只有当用户想要它,所以我不能使用style =“display:none” – raj

回答

2

你看过jQuery(http://jquery.com/)吗?这是非常简单易学,你只想做:

在你的HTML头

,只需添加

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> 

然后修改你的函数由

function hideRow(checkbox) 
{ 
    if(confirm('This action can not be recovered, are you sure you want to HIDE this Candidate? ')) 
    { 
     $(this).closest("tr").remove(); 
     return true; 
    } 
    return false; 
} 
+0

不能没有jQuery的吗? – raj

+0

甚至这个查询不起作用,当我点击复选框,然后按OK按钮,行不会隐藏 – raj

+0

为什么这段代码不工作在我的文件 – raj

0

删除不jQuery的

function hideRow(checkbox) 
{ 
    if(confirm('This action can not be recovered, are you sure you want to HIDE this Candidate? ')) 
    { 
     var row = checkbox.parentNode.parentNode , table = row.parentNode; 
     table.removeChild(row); 
     return true; 
    } 
    return false; 
} 
+0

不,这也只是暂时的隐藏行,和以前一样 – raj

0

您正在通过将样式显示设置为none来临时隐藏该行。你的问题是一旦这行被隐藏,那么当重新加载操作完成时它不应该再次出现。

因此,为了永久隐藏行,您必须从数据库本身删除相应的用户记录。如果在数据库中删除,那么您将无法从数据库中获取相同的记录,因此重新加载页面时不会显示该行。

希望这个建议适合你。