我需要根据使用ajax在JavaScript函数中确定的虚拟机的状态来显示/隐藏或更改导航栏链接上的文本。导航栏非常简单如图所示:
<div class="container">
<nav id="navbar-example" class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<label class="navbar-text">Host Status</label>
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse bs-example-js-navbar-collapse">
<ul class="nav navbar-nav">
<li><a id="openConsole" href="#">Open Console</a></li>
<li><a id="powerAction" href="#">Power Off</a></li>
<li><a id="restart" href="#">Restart</a></li>
<li><a id="reclaim" href="#">Reclaim</a></li>
</ul>
</div>
</div>
</nav>
我试过的javascript函数:
function GetVMStatus (host) {
$.ajax({
url: "/SystemBuildRequests/GetVMStatus",
data: { hostname: host },
success: function (theStatus) {
$("#vmStatus").text(theStatus.Status);
$("#memoryAmt").text(theStatus.MemoryAmt + "GB");
$("#cpuCount").text(theStatus.Cores);
$("#storageAmt").text(theStatus.ProvisionedSpace + "GB");
$("#uptime").html(theStatus.Uptime);
}
});
if ($("#vmStatus").text() == "running")
{
$("#reclaim").attr("style", "display:none");
$("#powerAction").text("Power Off");
}
else
{
$("#reclaim").attr("style", "display:block");
$("#powerAction").text("Power On");
}
}
我尝试使用jquery函数.show()和.hide(),它们具有相同的结果。我对CSS知之甚少,以及它如何适用于这种情况。宁愿有一个基于jquery的解决方案。
提前谢谢!