2017-08-04 95 views
-1

我似乎無法弄清楚我做錯了什麼。我想知道是否有人可以給我一些建議。我從here得到了代碼,但是我添加了我的代碼,並用文件夾中的文件替換了名稱。我正在努力讓網站上的任何人都可以點擊文件的名稱,並且它與我向您展示的鏈接一樣。我有一部分工作,但不理解爲什麼它不像鏈接那樣工作。從無文件夾的文件夾搜索框

<!DOCTYPE html> 
<html> 
<head> 
<style> 
* { 
    box-sizing: border-box; 
} 

#myInput { 
    background-image: url('/css/searchicon.png'); 
    background-position: 10px 10px; 
    background-repeat: no-repeat; 
    width: 100%; 
    font-size: 16px; 
    padding: 12px 20px 12px 40px; 
    border: 1px solid #ddd; 
    margin-bottom: 12px; 
} 

#myTable { 
    border-collapse: collapse; 
    width: 100%; 
    border: 1px solid #ddd; 
    font-size: 18px; 
} 

#myTable th, #myTable td { 
    text-align: left; 
    padding: 12px; 
} 

#myTable tr { 
    border-bottom: 1px solid #ddd; 
} 

#myTable tr.header, #myTable tr:hover { 
    background-color: #f1f1f1; 
} 
</style> 
</head> 
<body> 

<h2>My Customers</h2> 

<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for names.." title="Type in a name"> 

<table id="myTable"> 
    <tr class="header"> 
    <th style="width:60%; align:center;">Name</th> 
    </tr> 
    <tr> 
    <?php 
if ($file = opendir('C:/wamp/www/example.com/Library')) { 

    while (false !== ($entry = readdir($file))) { 
     if ($entry != "." && $entry != "..") { 
print "  
<td href='#'><a href='http://qlhc3kppkxushjyg.onion/example.com/Library/$entry'>$entry</br></a></td> 
"; 
     } 
    } 
     closedir($file); 
} 

?> 
    </tr> 
</table> 


<script> 
function myFunction() { 
    var input, filter, table, tr, td, i; 
    input = document.getElementById("myInput"); 
    filter = input.value.toUpperCase(); 
    table = document.getElementById("myTable"); 
    tr = table.getElementsByTagName("tr"); 
    for (i = 0; i < tr.length; i++) { 
    td = tr[i].getElementsByTagName("td")[0]; 
    if (td) { 
     if (td.innerHTML.toUpperCase().indexOf(filter) > -1) { 
     tr[i].style.display = ""; 
     } else { 
     tr[i].style.display = "none"; 
     } 
    }  
    } 
} 
</script> 

</body> 
</html> 
+0

什麼問題,錯誤? – Spectarion

+0

它沒有顯示任何錯誤;然而,當輸入關鍵字時,它應該彈出所有匹配它的關鍵字;儘管如此,它並不像那樣工作。我在那裏發佈的鏈接是我想要的,我想知道是否有人有想法或建議。非常感謝。 –

回答

1

這是它。它工作得很好。只是一件事..請不要使用像$file = opendir('C:/wamp/www/example.com/Library')這樣的絕對路徑,請使用像$file = opendir('Library')這樣的相對路徑。這意味着您的當前目錄有此腳本和一個名爲的庫其中包含您要過濾的所有條目。

示例目錄結構:

 

    htdocs/ 
    ├── Library/ 
    │ ├── John.txt 
    │ ├── Scott.txt 
    │ └── Anna.txt 
    └── index.php (this script) 

腳本:

<!DOCTYPE html> 
<html> 
    <head> 
     <style> 
     * { 
      box-sizing: border-box; 
     } 

     #myInput { 
      background-image: url('/css/searchicon.png'); 
      background-position: 10px 10px; 
      background-repeat: no-repeat; 
      width: 100%; 
      font-size: 16px; 
      padding: 12px 20px 12px 40px; 
      border: 1px solid #ddd; 
      margin-bottom: 12px; 
     } 

     #myTable { 
      border-collapse: collapse; 
      width: 100%; 
      border: 1px solid #ddd; 
      font-size: 18px; 
     } 

     #myTable th, #myTable td { 
      text-align: left; 
      padding: 12px; 
     } 

     #myTable tr { 
      border-bottom: 1px solid #ddd; 
     } 

     #myTable tr.header, #myTable tr:hover { 
      background-color: #f1f1f1; 
     } 
    </style> 
</head> 
    <body> 
     <h2>My Customers</h2> 
     <input type="text" id="myInput" onkeyup="filter()" placeholder="Search for names.." title="Type in a name"> 
     <table id="myTable"> 
      <tr class="header"> 
       <th style="width:60%; align:center;">Name</th> 
      </tr> 
      <?php 
       if ($file = opendir('C:/wamp/www/example.com/Library')) { 
        while (false !== ($entry = readdir($file))) { 
         if ($entry != "." && $entry != "..") { ?> 
          <tr> 
           <td href='#'> 
            <a href='http://qlhc3kppkxushjyg.onion/example.com/Library/<?php echo $entry; ?>'><?php echo $entry; ?></a> 
           </td> 
          </tr> 
         <?php } 
        } 
        closedir($file); 
       } 
      ?> 
     </table> 
     <script> 
      function filter() { 
       var input, filter, table, tr, td, i; 
       input = document.getElementById("myInput"); 
       filter = input.value.toUpperCase(); 
       table = document.getElementById("myTable"); 
       tr = table.getElementsByTagName("tr"); 
       for (i = 0; i < tr.length; i++) { 
        td = tr[i].getElementsByTagName("td")[0]; 
        if (td) { 
         if (td.innerHTML.toUpperCase().indexOf(filter) > -1) { 
          tr[i].style.display = ""; 
         } else { 
          tr[i].style.display = "none"; 
         } 
        }  
       } 
      } 
     </script> 
    </body> 
</html> 
+1

感謝您的提示,我將刪除圖書館的路徑,非常感謝。 –