热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

在jQuery中进行简单搜索无法正常工作-SimplesearchinjQuerynotworkingproperly

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 个解决方案

#1


0  

The \b pattern matches a location at a word boundary.

\ b模式匹配单词边界处的位置。

To allow in-word matches, just remove all \\b in your patterns.

要允许单词匹配,只需删除模式中的所有\\ b。


推荐阅读
author-avatar
我确实是一只猪_143_267
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有