我想做的是遍历表的每一行,并将每行的第一个单元格与上一行的第一个单元格进行比较。似乎应该很简单,但我肯定是这样,但是现在我迷失了。.这就是我所拥有的..我想我很亲密,但无法完全弄清我的错。
$("tr td:first-child").each(function(){
if(($(this).text()) == lastId){
console.log("YEP, the same");
}else{
console.log("no, different Id");
}
var lastId = $(this).text();
});
您需要将变量lastId保留在另一个作用域中。在这里,它在每次迭代中都会丢失。
var lastId;
$("tr td:first-child").each(function(){
if(($(this).text()) == lastId){
console.log("YEP, the same");
}else{
console.log("no, different Id");
}
lastId = $(this).text();
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句