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?
5 Answers
Reset to default 4Don'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
版权声明:本文标题:javascript - Exact value of two variables need to be compared in JQuery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743894430a2557519.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论