Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jquery基于精确匹配显示行_Javascript_Jquery_Jquery Selectors - Fatal编程技术网

Javascript jquery基于精确匹配显示行

Javascript jquery基于精确匹配显示行,javascript,jquery,jquery-selectors,Javascript,Jquery,Jquery Selectors,因此,我试图根据精确匹配显示几行。我不想只显示包含,因为21和12都与“1”匹配 下面是javascript: $("tr:has(.logType:contains('" + curr + "'))").filter(function () { return $(this).text == curr; }).removeAttr("style"); 以及html: <table> <thead> <tr>

因此,我试图根据精确匹配显示几行。我不想只显示包含,因为21和12都与“1”匹配

下面是javascript:

$("tr:has(.logType:contains('" + curr + "'))").filter(function () {
    return $(this).text == curr;
}).removeAttr("style");
以及html:

<table>
    <thead>
        <tr>
            ...
            <th class="logType">
                Log Type
                <!-- some options -->
                </select>
            </th>
    <thead>
    <tbody>
          ...
          <tr>
             <td class="logType">
                <!-- some content -->
             </td>
          </tr>
    </tbody>
当前,jquery中的条件永远不会返回true,即使存在多个精确匹配。

如果您检查.text提供给您的内容,您会发现它不匹配,因为它包含所有空格:

console.log($(this).text())
给予

您可以对.text进行修剪以进行比较,例如:

var curr=abc var items=$tr:has.logType:包含“+curr+”.filterfunction{ console.log$this.text console.log$this.text.length/>3 返回$this.text.trim==curr; } alertitems.length 日志类型 abc
"          Log Type            "