我正在使用这个脚本来过滤表格中的结果。问题是电话号码的格式为 xxx-xxx-xxxx,当您搜索时,如果省略连字符,搜索将错过该条目。有没有办法在搜索中忽略连字符?我试过修改省略空格的行,但我根本无法让它工作。任何帮助,将不胜感激。
$(document).ready(function () {
var $orders = $('#orders tbody .filter');
$('#filtersearch').keyup(function () {
var val = $.trim($(this).val()).replace(/ +/g, ' ').toLowerCase();
$orders.closest('tr').hide().each(function () {
if ($('td', this).filter(function () {
var text = $(this).text().replace(/-\s+/g, ' ').toLowerCase();
return text.indexOf(val) != -1;
s
}).length > 0) $(this).show();
})
});
$('#filtersearch').keyup();
});
我的代码
// connect to the database
include('connect-db.php');
// get results from database
$result = mysql_query("SELECT * FROM orders ORDER BY Name ASC")
or die(mysql_error());
// loop through results of database query, displaying them in the table
while($row = mysql_fetch_array( $result )) {
// echo out the contents of each row into a table
echo "<tr>";
echo '<td>' . $row['date'] . '</td>';
echo '<td class="filter">' . $row['Name'] . '</td>';
echo '<td class="filter">' . $row['Company'] . '</td>';
echo '<td class="filter">' . $row['Phone'] . '</td>';
echo '<td><img src="images/icons/'.$row['Location'].'.png"></td>';
echo '<td><a href="delete.php?id=' . $row['id'] . '"><img src="images/icons/checkmark.png"></a></td>';
echo "</tr>";
}
?>
</tbody>