Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/463.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/87.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 如果包含精确匹配,则隐藏表td_Javascript_Jquery_Html_Coding Style - Fatal编程技术网

Javascript 如果包含精确匹配,则隐藏表td

Javascript 如果包含精确匹配,则隐藏表td,javascript,jquery,html,coding-style,Javascript,Jquery,Html,Coding Style,我需要隐藏我的所有表td,如果它们只包含符号“%” 我有两种结果: <td>%</td> <td>1%</td> 我需要知道怎么做。 谢谢你试着用每一个喜欢的 $('#results table tbody tr td').each(function(){ if($(this).text() == "%") { $(this).hide(); } }); 尝试使用每种方法 $('#results table

我需要隐藏我的所有表td,如果它们只包含符号“%”

我有两种结果:

<td>%</td>
<td>1%</td>
我需要知道怎么做。
谢谢你

试着用
每一个
喜欢的

$('#results table tbody tr td').each(function(){
     if($(this).text() == "%") {
         $(this).hide();
     }
});

尝试使用
每种
方法

$('#results table tbody tr td').each(function(){
     if($(this).text() == "%") {
         $(this).hide();
     }
});
我将使用:

下面是一个示例。

我将使用:

这里有一个例子可以演示。

试试这个

$('#results table tbody tr td').each(function(){
     if($(this).text().indexOf('%')!=-1)
     {
         $(this).hide();
     }
});
试试这个

$('#results table tbody tr td').each(function(){
     if($(this).text().indexOf('%')!=-1)
     {
         $(this).hide();
     }
});

我的观点是正确的,它确实返回jQuery对象。这将是更好的解决方案。@Stan只需在
.hide()
@RGraham之前调用
.parent()
,非常感谢。现在它很完美了。我站对了,它确实返回了一个jQuery对象。这将是更好的解决方案。@Stan只需在
.hide()
@RGraham之前调用
.parent()
,非常感谢。现在它完美了。这将隐藏所有包含
%
。包括他不想隐藏的
%1
。这将隐藏其中任何包含
%
。包括他不想隐藏的
%1
。您的jQuery是错误的,您对它为什么错误的想法也是错误的。您已经编写了两个完全独立的jQuery选择器。
if
中的一个与处于
if
状态的一个无关。两次都选择了不同的元素。在
if
中,您需要引用第一个
jQuery(…)
找到的结果,方法是将它们存储在一个变量中,或者使用
每个
/
过滤器进行迭代。您已经编写了两个完全独立的jQuery选择器。
if
中的一个与处于
if
状态的一个无关。两次都选择了不同的元素。在
if
中,您需要引用第一个
jQuery(…)
找到的结果,方法是将它们存储在一个变量中,或者使用
每个
/
过滤器
/等对它们进行迭代。