Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/455.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/2/jquery/78.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_Wordpress - Fatal编程技术网

Javascript 使用Jquery隐藏范围匹配条件中的所有字符串

Javascript 使用Jquery隐藏范围匹配条件中的所有字符串,javascript,jquery,wordpress,Javascript,Jquery,Wordpress,我试图从页面中隐藏所有$0.00字符串,并尝试过,但未成功。我得到错误:TypeError:hidepricenull.each不是一个函数。我正在wordpress中使用它 HTML 预期产出: 从跨距中隐藏2个文本 <span class="amount"></span> <span class="amount"></span> 您应该迭代项目并检查其文本,您可以尝试以下方法: jQuery(document).ready(function(

我试图从页面中隐藏所有$0.00字符串,并尝试过,但未成功。我得到错误:TypeError:hidepricenull.each不是一个函数。我正在wordpress中使用它

HTML

预期产出:

从跨距中隐藏2个文本

<span class="amount"></span>
<span class="amount"></span>

您应该迭代项目并检查其文本,您可以尝试以下方法:

jQuery(document).ready(function($) {
    var hidepricenull = $('span.amount');
    hidepricenull.each(function(){
        if($(this).text() == '£200.00') {
            $(this).hide(); 
        }
    });
});

您应该迭代项目并检查其文本,您可以尝试以下方法:

jQuery(document).ready(function($) {
    var hidepricenull = $('span.amount');
    hidepricenull.each(function(){
        if($(this).text() == '£200.00') {
            $(this).hide(); 
        }
    });
});
hidepricenull值是一个字符串,它是第一项的文本值,因为调用文本,但您需要集合并访问每个项的文本:

jQuery(document).ready(function ($) {
    var hidepricenull = $('span.amount');
    hidepricenull.each(function () {
        if ($(this).text() == '£200.00') {
            $(this).hide();
        }
    });
});
注意:您还可以开始使用jQuery的相当方便的作用域DOM就绪快捷方式:

jQuery(function ($) {
    var hidepricenull = $('span.amount');
    hidepricenull.each(function () {
        if ($(this).text() == '£200.00') {
            $(this).hide();
        }
    });
});
注意:不再需要temp变量,您可以使用过滤器:

jQuery(function ($) {
    $('span.amount').filter(function () {
        return $(this).text() == '£200.00';
    }).hide();
});
更新以支持多个值:

jQuery(function ($) {
    $('span.amount').filter(function () {
        var text = $(this).text();
        return text == '£200.00' || text == '£100.00';
    }).hide();
});
对于许多值,更新以支持比字符串更快的数值比较:

jQuery(function ($) {
    $('span.amount').filter(function () {
        var value = parseFloat($(this).text().substring(1));
        return value == 200 || value == 100 || value == 50;
    }).hide();
});
hidepricenull值是一个字符串,它是第一项的文本值,因为调用文本,但您需要集合并访问每个项的文本:

jQuery(document).ready(function ($) {
    var hidepricenull = $('span.amount');
    hidepricenull.each(function () {
        if ($(this).text() == '£200.00') {
            $(this).hide();
        }
    });
});
注意:您还可以开始使用jQuery的相当方便的作用域DOM就绪快捷方式:

jQuery(function ($) {
    var hidepricenull = $('span.amount');
    hidepricenull.each(function () {
        if ($(this).text() == '£200.00') {
            $(this).hide();
        }
    });
});
注意:不再需要temp变量,您可以使用过滤器:

jQuery(function ($) {
    $('span.amount').filter(function () {
        return $(this).text() == '£200.00';
    }).hide();
});
更新以支持多个值:

jQuery(function ($) {
    $('span.amount').filter(function () {
        var text = $(this).text();
        return text == '£200.00' || text == '£100.00';
    }).hide();
});
对于许多值,更新以支持比字符串更快的数值比较:

jQuery(function ($) {
    $('span.amount').filter(function () {
        var value = parseFloat($(this).text().substring(1));
        return value == 200 || value == 100 || value == 50;
    }).hide();
});

通过使用jquery,您可以简单地完成这项工作

$('span:contains("£0.00")').hide();

通过使用jquery,您可以简单地完成这项工作

$('span:contains("£0.00")').hide();

@TrueBlueAusie完成。因为您需要为$each;创建一个集合;hidepricenull是一个字符串,而不是集合。在下面添加了一个过滤器版本,该版本应该更有效:@TrueBlueAusie Done。因为您需要为$.each创建一个集合;hidepricenull是一个字符串,而不是一个集合。下面添加了一个过滤器版本,这应该会稍微更有效:是什么让你这么做的?现在有3个相同的答案:抱歉,在发布之前没有看到以前的答案。。就在一分钟之内,是什么让你耽搁了?现在有3个相同的答案:抱歉,在发布之前没有看到以前的答案。。就在一分钟之内,只是短一点。。。速度差可以忽略不计。如果我想隐藏200.00英镑之外的100.00英镑,那么在第三个位置,一次将不可能添加2次返回。啊哈,我明白了,因此,对于10.000个元素来说,性能最好的是哪一个元素?@user3467855:Example更新为将字符串转换为数值,并进行匹配检查,如<200等。对于许多值,数值匹配速度更快。只是更短。。。速度差可以忽略不计。如果我想隐藏200.00英镑之外的100.00英镑,那么在第三个位置,一次将不可能添加2次返回。啊哈,我明白了,因此,对于10.000个元素来说,性能最好的是哪一个元素?@user3467855:Example更新为将字符串转换为数值,并进行匹配检查,如<200等。对于许多值,数值匹配会更快。