2012-12-24 74 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來臨時隱藏該行。你的問題是一旦這行被隱藏,那麼當重新加載操作完成時它不應該再次出現。

因此,爲了永久隱藏行,您必須從數據庫本身刪除相應的用戶記錄。如果在數據庫中刪除,那麼您將無法從數據庫中獲取相同的記錄,因此重新加載頁面時不會顯示該行。

希望這個建議適合你。