答案 0 :(得分:1)
您可以在按钮上添加一个监听器,当您按下该按钮时,可以更改它的颜色。 您可以这样做:
var button = document.getElementById('myButton');
button.addEventListener('click', function(e) {
button.className = 'selected';
});
您还可以更改按钮的CSS类,而不是直接使用javascript更改其颜色:
.selected
{
background-color: red;
}
CSS:
[Route("{title}")]
public ActionResult Index(string title)
{
return View();
}
答案 1 :(得分:0)
您可以使用以下javascript执行此操作:
document.getElementById("elementId").style.backgroundColor = "blue";
答案 2 :(得分:0)
如果您使用Chrome作为网络浏览器,则可以打开控制台并复制以下代码:
document.getElementById("nav-questions").style.backgroundColor = "red"
答案 3 :(得分:0)
尝试此答案
function getElementById_Click() {
document.getElementById("example").style.backgroundColor = "red";
}
function getElementsByClassName_Click() {
document.getElementsByClassName("example")[2].style.backgroundColor = "red";
}

<!DOCTYPE html>
<html>
<head>
<style>
.example, #example {
border: 1px solid black;
margin: 5px;
}
</style>
</head>
<body>
<div class="example ">
This is getElementsByClassName Example 1
</div>
<div id="example">
This is getElementById Example
</div>
<div class="example">
This is getElementsByClassName Example 2
</div>
<div class="example">
This is getElementsByClassName Example 3
</div>
<div class="example">
This is getElementsByClassName Example 4
</div>
<button type="button" onclick="getElementById_Click()" >GET ELEMENT BY ID</button>
<button type="button" onclick="getElementsByClassName_Click()" >GET ELEMENT BY CLASS</button>
</body>
</html>
&#13;