css和js處理隔行換色的問題
阿新 • • 發佈:2017-09-08
ron -o user XML use type scala tex sha
- <html>
- <head>
- <meta charset="utf-8">
- <meta name="" content="content">
- <meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=no"/>
- <title></title>
- <link rel="stylesheet" type="text/css" href="">
- <script src="js/jquery1.8.3.min.js"></script>
- </head>
- <script>
- /*$(document).ready(function(){
- $(‘.product_tit:even‘).css({"color":"#21c178"});
- $(‘.product_tit:odd‘).css({"color":"#459ee6"});
- })*/
- </script>
- <div> <span style="white-space:pre"> </span><style>
- <span style="white-space:pre"> </span>#list2:nth-of-type(odd) .product_tit{color:#21c178}
- <span style="white-space:pre"> </span>#list2:nth-of-type(even) .product_tit{color:#459ee6}
- <span style="white-space:pre"> </span></style> </div> <body>
- <style type="text/css">
- .list1:nth-of-type(odd){ color:#ffcc00;}
- .list1:nth-of-type(even){ color:#00ccff;}
- </style>
- <div>
- <ul>
- <li class="list1">111111111111111111111111111</li>
- <li class="list1">222222222222222222222222222</li>
- <li class="list1">333333333333333333333333333</li>
- <li class="list1">444444444444444444444444444</li>
- <li class="list1">555555555555555555555555555</li>
- <li class="list1">666666666666666666666666666</li>
- </ul>
- <hr />
- <div id="list2">
- <div class="product_tit">7777777777777777777777777777</div>
- </div>
- <div id="list2">
- <div class="product_tit">8888888888888888888888888888</div>
- </div>
- <div id="list2">
- <div class="product_tit">9999999999999999999999999999</div>
- </div>
- <div id="list2">
- <div class="product_tit">0000000000000000000000000000</div>
- </div>
- <div id="list2">
- <div class="product_tit">7777777777777777777777777777</div>
- </div>
- </div>
- </body>
- </html>
備註:自己添加jquery
錯誤的css:
[html] view plain copy
- <style>
- .product_tit:nth-of-type(odd){color:#21c178}
- .product_tit:nth-of-type(odd){color:#459ee6}
- </style>
錯誤的原因:class=product_tit的每個元素都沒有兄弟節點,nth-of-type並不會起作用
css和js處理隔行換色的問題