HTML part of the code:
< ;li>Change the background color when the mouse passes over
- Change the background color when the mouse passes over
- Change the background color when the mouse passes over
- Change the background color when the mouse passes over
Javascript part of the code:
When the mouse passes over, add li class="current" class, when the mouse leaves, remove this class to achieve the purpose of changing the background color
window.onload = function() {
var lis = document.getElementsByTagName("li");
for (var i=0; ilis[i].onmouseover = function() {
this.setAttribute("class", "current");
}
lis[i].onmouseout = function() {
this.setAttribute("class", "");
}
}
}
Css part code:
ul li.current {
background-color:red;
cursor:pointer;
}
The above code is mainly to facilitate everyone to know more about js. A css-implemented version is provided below.
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn