我正在使用此脚本来过滤表格中的结果。问题是电话号码格式为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>
答案 0 :(得分:0)
999-999-999".replace(/-\s+/g, ' ')
将检查 连字符和空格字符。用它来检查其中一个:
"999-999-999".replace(/[-\s]+/g, ' ') // "999 999 999"