我想创建一个过滤器,它作用于表中的所有列,特别是忽略电话号码的格式。
我认为最简单的方法是将电话号码的数字部分添加到最近的数字中
TD
文本搜索功能按预期工作,但我似乎无法让数据属性搜索工作。
$(document).ready(function() {
$("#inputSearch").on("keyup", function() {
var value = $(this).val().toLowerCase();
$("#tableContacts tr").filter(function() {
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
});
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="inputSearch" type="text" placeholder="Search..." autofocus><br/>
<table id="tableContacts" class="table">
<thead>
<tr>
<th>name</th>
<th>domain</th>
<th>email</th>
<th>work</th>
<th>mobile</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="/contacts/5">Morticia Addams</a></td>
<td>ghouhl.io</td>
<td><a href="mailto:Morticia.Addams@ghouhl.io" class="text-truncate">Morticia.Addams@ghouhl.io</a></td>
<td data-work-telephone="88855512342"><a href="tel:(888) 555-1234 x2">(888) 555-1234 x2</a></td>
<td data-mobile-telephone="8885552222"><a href="tel:(888) 555-2222">(888) 555-2222</a></td>
</tr>
<tr>
<td><a href="/contacts/6">Gomez Addams</a></td>
<td>ghouhl.io</td>
<td><a href="mailto:Gomez.Addams@ghouhl.io" class="text-truncate">Morticia.Addams@ghouhl.io</a></td>
<td data-work-telephone="88855512341"><a href="tel:(888) 555-1234 x1">(888) 555-1234 x1</a></td>
<td data-mobile-telephone="8885553333"><a href="tel:(888) 555-3333">(888) 555-3333</a></td>
</tr>
</tbody>
</table>