gpt4 book ai didi

jquery - 如何使用 Jquery 循环每个表并在运行时写入状态?

转载 作者:行者123 更新时间:2023-11-28 07:19:13 25 4
gpt4 key购买 nike

下面的代码有助于获取每个表中的行数。

$(document).ready(function(){

$(".assertionTable").each(function(){

var test=$(this).find("tr").length;
document.write(test);

});

});

但是,我遇到了另一个问题。我只想获取单元格值,如果单元格包含“FAILED”关键字,则它需要在运行时写入状态。请在下面找到示例代码:

$(document).ready(function(){

$(".assertionTable").each(function(){

var test=$(this).find("tr td:last-child").is(':contains("FAILED")'); //Just assume that I have two table in a page, and one table contains "FAILED", and other table not contains that keyword. So It returns true, false in output console which is expected.

基于该值,我只需要将主要状态写为通过或失败。假设每个表都有自己的“.mainStatus”类。

       if(test==true)
{
$(".mainStatus").html("FAILED");
}
else
{
$(".mainStatus").html("PASSED");
}

});

});

不幸的是,它不起作用。我只是想尝试一下自己,这就是我发布的与我的问题类似的查询。我希望你能理解并帮助我。

我没有任何 id 属性,我只想使用类来完成此操作。

请帮帮我。提前致谢。

请查找更多信息:How to iterate the elements using index in jquery?

-萨西

最佳答案

请试试这个:

$(document).ready(function(){

$(".assertionTable").each(function(){

var test=$(this).find("tr td:last-child").is(':contains("FAILED")');

var divassertiondatTable = $(this).parent();
var prevTestStatusDiv = divassertiondatTable.prev(".teststatus");

if(test==true)
{
$(prevTestStatusDiv).find(".status").html("FAILED");
}
else
{
$(prevTestStatusDiv).find(".status").html("PASSED");
}

});
});

关于jquery - 如何使用 Jquery 循环每个表并在运行时写入状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32179242/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com