admin管理员组

文章数量:1353186

I have the following piece of code:

$j('#row1').find('span.grpid').each(function() {
        groupIdNew = groupId.split("~")[0];
        var value = $j(this).html();
        if (value.match(groupIdNew)){
            $j(this).parents('tr').remove();
        }
    });

Problem is I need the value to exactly equal groupIdNew. (Eg: test_11 should not match test_1 as is the case with .match(), but exactly equal test_11). How do I do this?

I have the following piece of code:

$j('#row1').find('span.grpid').each(function() {
        groupIdNew = groupId.split("~")[0];
        var value = $j(this).html();
        if (value.match(groupIdNew)){
            $j(this).parents('tr').remove();
        }
    });

Problem is I need the value to exactly equal groupIdNew. (Eg: test_11 should not match test_1 as is the case with .match(), but exactly equal test_11). How do I do this?

Share Improve this question edited Apr 29, 2013 at 9:59 Kasyx 3,20022 silver badges32 bronze badges asked Apr 29, 2013 at 9:53 Bharath NaiduBharath Naidu 1953 gold badges6 silver badges15 bronze badges
Add a ment  | 

5 Answers 5

Reset to default 4

Don't use match, just pare them:

if(value === groupIdNew){

Or if you need to trim whitespace:

if($j.trim(value) === groupIdNew){

Use the double equals sign?

if (value == groupIdNew) {

Use the triple if you want to be strict about the data types.

You can use if(value === groupIdNew){

you can use the triple if you want to be strict about the data type

You can just do it using the equal operator (===):

if (value === groupIdNew){

Here's the full code:

$j('#row1').find('span.grpid').each(function() {
        groupIdNew = groupId.split("~")[0];
        var value = $j(this).html();
        if (value === groupIdNew){
            $j(this).parents('tr').remove();
        }
});

use === operator

 if (value === groupIdNew){
        $j(this).parents('tr').remove();
    }

本文标签: javascriptExact value of two variables need to be compared in JQueryStack Overflow