<ul>
<li class="red"><a href="javascript:void(0)">项目一</a></li>
<li class="green"><a href="javascript:void(0)">项目二</a></li>
<li class="green"><a href="javascript:void(0)">项目三</a></li>
<li class="green"><a href="javascript:void(0)">项目四</a></li>
</ul>
$(function () {
$.each($("li"), function (i, o) {
$(this).children("a").click(function () {
allhide();
$(this).parent("li").attr("class", "red");
});
if ($(this).attr("class") != "red") {
$(this).mouseenter(function () {
$(this).attr("class", "red");
});
$(this).mouseleave(function () {
$(this).attr("class", "green");
});
}
});
});
function allhide() {
$.each($("li"), function (i, o) {
$(this).attr("class", "green");
});
}
<style type="text/css">
li
{
width: 80px;
list-style-type: none;
}
.red
{
background-color: Red;