<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<!-- <META HTTP-EQUIV="expires" CONTENT="Wed, 26 Feb 2019 8:22:57 GMT"> -->
<title></title>
<style>
.focus {color: blue;}
.index{
color: blue;
}
li{
list-style: none;
cursor: pointer;
}
#test li{
float: left;
margin-right: 20px;
}
#test li:hover{
color:red;
}
</style>
</head>
<body>
<ul id="test">
<li class="index">导航1</li>
<li>导航2</li>
<li>导航3</li>
<li>导航4</li>
<li>导航5</li>
<li>导航6</li>
<li>导航7</li>
</ul>
</body>
</html>
<script src="http://code.jquery.com/jquery-1.3.1.min.js"></script>
<script>
$(document).ready(function(){
$('#test li').click(function(){
console.log( $(this));
if ($(this).hasClass('focus')) {
return true;
} else {
$('#test li').removeClass('focus');
$('#test li').removeClass('index');
$(this).addClass('focus');
}
});
});
</script>
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交