Javascript jquery基于精确匹配显示行
因此,我试图根据精确匹配显示几行。我不想只显示包含,因为21和12都与“1”匹配 下面是javascript: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>
$("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 "