javascript - How to change the color of the navigation bar in Javascript?
问题描述
Like in the stack overflow navigation bar
if i click on questions the color of it should be change instead of orange line..
解决方案
你可以在你的按钮上添加一个监听器,当你按下它时,改变它的颜色。例如,您可以这样做:
var button = document.getElementById('myButton');
button.addEventListener('click', function(e) {
button.style.backgroundColor = "red";
});
您还可以更改按钮的 CSS 类,而不是直接使用 javascript 更改其颜色:
var button = document.getElementById('myButton');
button.addEventListener('click', function(e) {
button.className = 'selected';
});
CSS:
.selected
{
background-color: red;
}
推荐阅读
- solr - qtp在solr日志中代表什么
- python-3.x - 在遍历字符串的 for 循环中向前看?
- mysql - 如何加密 CentOS 中现有的 mariadb 表?
- sql - 如何在代表季节的 varchar 列上使用聚合函数 (MAX)
- reactjs - 右键单击树项时,菜单的一部分显示在 React 中的树项后面
- python - 如何拆分多页 TIFF
- html - 使用溢出时伪元素不可见
- nginx - Nginx 替换模块没有被调用
- javascript - 设置视频的 src 会带来 DOMException 错误
- arm - Cortex-R5 PMU 周期计数器未正确计算时间