作者:我确实是一只猪_143_267 | 来源:互联网 | 2023-09-14 01:16
IvejQueryscriptthatImusingtosearchthroughhtmltablesandhiderowsthatarenotmatching
I've jQuery script that I'm using to search through html tables and hide rows that are not matching entered string.
我用jQuery脚本来搜索html表并隐藏与输入字符串不匹配的行。
But it have some problem:
I have some elements with string 'Kable i przewody' and my search is working properly when I use strings with one letter or starting with any word in string ie.: 'Ka', 'prze' etc.
但它有一些问题:我有一些字符串'Kable i przewody',当我使用一个字母的字符串或以字符串中的任何单词开头时我的搜索正常工作即:'Ka','prze'等。
But It's not working with some strings using middle letters from words: 'able', 'rze', 'ody'.
但它并没有使用一些字符串,使用单词的中间字母:'able','rze','ody'。
This here is my code, please help:
这是我的代码,请帮忙:
var query = getUrlParameter('q');
var $rows = $('.tabelapatrnerzy tr');
$('#szukaj').click(function() {
var val = '^(?=.*\\b' + $.trim($('#wpisywane').val()).split(/\s+/).join('\\b)(?=.*\\b') + ').*$',
reg = RegExp(val, 'i'),
text;
$rows.show().filter(function() {
text = $(this).text().replace(/\s+/g, ' ', /ą/i, '', /ź/i, 'z', /ż/i, 'z',/ó/i ,'o', /ł/i, 'l', /ń/i, 'n', /ć/i, 'c', /ę/i, 'e', /ś/i, 's');
return !reg.test(text);
}).hide();
});
if (query) {
var val = '^(?=.*\\b' + $.trim(query).split(/\s+/).join('\\b)(?=.*\\b') + ').*$',
reg = RegExp(val, 'i'),
text;
$rows.show().filter(function() {
text = $(this).text().replace(/\s+/g, ' ', /ą/i, '', /ź/i, 'z', /ż/i, 'z',/ó/i ,'o', /ł/i, 'l', /ń/i, 'n', /ć/i, 'c', /ę/i, 'e', /ś/i, 's');
return !reg.test(text);
}).hide();
}
1 个解决方案