gpt4 book ai didi

javascript - 如何在 JavaScript 中更改 Span 的类

转载 作者:行者123 更新时间:2023-12-03 10:19:28 25 4
gpt4 key购买 nike

我有一个ul元素中包含如下所示的项目,我想更改 span元素的类在 'glyphicon-ok greenstatus' 之间和'glyphicon-remove redstatus' .

这是我的 HTML 和 JS,我想在其中更改 li id="overviewlink"根据我的帖子返回的条件跨度类。

$.post(url, {
id: id,
summary: summary,
complete: completed
}, function(response) {
var jsonObj = JSON.parse(response);

if (jsonObj.Completed == 'complete') {
// change span class in overview to 'glyphicon-ok greenstatus'
} else {
// change span class in overview to 'glyphicon-remove redstatus'
}

if (jsonObj.StepsToList == '0') {
//change to enum drop down
} else {
// change enum drop down to message showing number of steps
}
$("#successmessage").show().delay(5000).fadeOut();
})
.fail(function() {
alert("error");
});
<ul id="managelinks" class="nav nav-stacked">
<li id="overviewlink">
<a href="#overviewlink">Overview
@if (Model.Overview.Completed == ListingComplete.Complete)
{
<span class="glyphicon glyphicon-ok greenstatus" aria-hidden="false"></span>
}
else
{
<span class="glyphicon glyphicon-remove redstatus" aria-hidden="false"></span>
}
</a>
</li>
<li id="detailslink">
<a href="#detailslink">Details
@if (Model.Details.Completed == ListingComplete.Complete)
{
<span class="glyphicon glyphicon-ok greenstatus" aria-hidden="false"></span>
}
else
{
<span class="glyphicon glyphicon-remove redstatus" aria-hidden="false"></span>
}
</a>
</li>
</ul>

最佳答案

由于您使用的是 jQuery:

完整文档:http://api.jquery.com/

关于javascript - 如何在 JavaScript 中更改 Span 的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29711878/

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