2017-09-28 47 views
0

我有一個簡單的搜索功能,過濾表。它工作正常。 但是,它也隱藏標題。如何從搜索中省略標題?任何幫助將不勝感激。onkeyup函數刪除表頭

PHP/HTML:

//Create a table to display the output 
    echo '<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for names..">'; 
    echo '<div class="table-responsive">'; 
    echo '<table id="myTable"><tr bgcolor="#cccccc"><td>Name</td><td>E-Mail Address</td><td>Office Phone</td><td>Mobile</td></tr>'; 

    //Populate the table from LDAP 
    echo "<tr><td>".$LDAP_FirstName." " .$LDAP_LastName."</td><td><a class='one' href='mailto:" .$LDAP_InternetAddress. "'>" .$LDAP_InternetAddress."</td><td>".$LDAP_OfficePhone."</td><td>".$LDAP_CellPhone."</td><tr>"; 
    echo("</table>"); 
    echo("</div>"); 

腳本:

function myFunction() { 
// Declare variables 
    var input, filter, table, tr, td, i; 
    input = document.getElementById("myInput"); 
    filter = input.value.toUpperCase(); 
    table = document.getElementById("myTable"); 
    tr = table.getElementsByTagName("tr"); 

// Loop through all table rows, and hide those who don't match the search query 
    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"; 
     } 
    } 
    } 
} 
+0

跳過第一個元素,也許簡單地用for代替for循環(i = 1; i gurvinder372

+0

*破壞手邊。回到noobville ......謝謝 – user2720970

回答

0

你的頭將是第一要素,所以在您的for循環

for (i = 1; i < tr.length; i++) //replace 0 with 1