Pure CSS method to realize interlaced color alternation, mouse over highlight color:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | <html>
<head>
<title></title>
<style type= "text/css" >
ul{list-style:none}
li:nth-child(odd){background-color:#eee}
li:hover{background-color:Yellow}
</style>
</head>
<body>
<ul>
<li>111</li>
<li>111</li>
<li>111</li>
<li>111</li>
<li>111</li>
<li>111</li>
<li>111</li>
</ul>
</body>
</html>
|
Copy after login
js method to realize interlaced color alternation, mouse over highlight color:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | <html>
<head>
<title></title>
<script src= "//cdn.bootcss.com/jquery/1.11.3/jquery.min.js" ></script>
<style type= "text/css" >
.alter-item {
background-color: #eee;
}
.hightlight {
background-color: Yellow;
}
</style>
<script type= "text/javascript" >
$( function () {
$( "ul li:odd" ).addClass( "alter-item" );
method1();
});
function method1() {
$( "ul li" ).hover( function () {
$(this).addClass( "hightlight" );
}, function () {
$(this).removeClass( "hightlight" )
});
}
function method2() {
$( "ul li" ).mouseover( function () {
$(this).addClass( "hightlight" ).siblings().removeClass( "hightlight" );
});
}
</script>
</head>
<body>
<ul>
<li>111</li>
<li>222222222</li>
<li>111</li>
<li>444444444444444444444</li>
<li>111</li>
<li>111</li>
<li>111</li>
</ul>
</body>
</html>
|
Copy after login