检查类元素是否具有相同的html内容

时间:2013-03-10 19:35:26

标签: jquery

我想检查一下类元素是否具有相同的html内容。

实施例

<span class="test">100</span>
<span class="test">100</span>
<span class="test">98</span>
<span class="test">100</span>
<span class="test">100</span>

我想知道某个元素是否有不同的内容,例如<{1}}数字

由于

3 个答案:

答案 0 :(得分:1)

尝试一些像这样的代码

$(".test").each(function(){
    var val = $(this).html();
    if(val!="100") alert(val);
});

DEMO VIEW

答案 1 :(得分:1)

这样做: -

$(".test").each(function() {
    if (Number($(this).text()) > 98)
        alert("Text contains > 98");
});

参考 LIVE DEMO

答案 2 :(得分:0)

应该这样做:

    var a = new Array();

    $('.test').each(function(index) {
        text = $(this).text();

        if ($.inArray(text, a) != -1) {
            $(this).hide();
        } else {
            a.push(text);
        }

    });

    return false;
相关问题