所有想要隱藏tr如果第一個字母的td:nth-child(1)不包含字母D, atm我的代碼只是隱藏它if所有的TDS不包含字母D. HTML:隱藏tr如果其td:nth-child()第一個字母不包含字母
HTML
<table id="myTable">
<thead>
<tr><th>Name</th><th>Lastname</th></tr>
</thead>
<tbody>
<tr><td>Zuri</td><td>Mam</td></tr>
<tr><td>Dima</td><td>Mam</td></tr>
<tr><td>Dato</td><td>Mik</td></tr>
<tr><td>AMD</td><td>Phen</td></tr>
</tbody>
</table>
<button id="hide">Filter by First letter D</button>
<button id="showAll">Show All</button>
jQuery的
$("#hide").click(function() {
$("#myTable tr:not(:has(th))").not(":contains(D)").hide();
});
$("#showAll").click(function() {
$("#myTable tr:not(:has(th))").show()
});
工作JSFiddle。 請幫忙, 謝謝!
得到td html(),並且只檢查第一個字符是否與 – Dibu
不使用包含,它檢查整個字符串 – Dibu