<html> <script type="text/javascript" src="jquery-1.9.1.js"></script> <body> <table> <tr class="bottom b-fffdee xinghao68"> <td> </td> <td class="t-left"> <a href="http://localhost:8080/BNCAR2/partsDetailAction?id=58" class="fc-blue"><img src="picture/parts/2014/1/13/138961178380789969.jpg" width="44" height="44" /> 单件商品2</a></td> <td></td> <td> </td> <td></td> <td></td> </tr> <tr class="bottom b-fffdee xinghao68"> <td> </td> <td class="t-left"> <a href="http://localhost:8080/BNCAR2/partsDetailAction?id=55" class="fc-blue"><img src="picture/parts/2014/1/9/138924733778756518.jpg" width="44" height="44" /> QQQQ</a></td> <td></td> <td> </td> <td></td> <td></td> </tr> <tr class="bottom b-fffdee xinghao68" > <td> </td> <td class="t-left"> <a href="http://localhost:8080/BNCAR2/partsDetailAction?id=45" class="fc-blue"><img src="picture/parts/none.jpg" width="44" height="44" /> aa</a></td> <td></td> <td> </td> <td></td> <td></td> </tr> </table> </body> <script type="text/javascript"> $(function(){ alert("AAA:"+$(".xinghao68")); alert("BBB:"+$(".xinghao68").length); $(".xinghao68").each(function(){ alert($(this).text()); }); }); </script> </html>
如果TR行class写成:<tr class="bottom b-fffdee"
class="xinghao68">,这样通过类选择器是取不到的,需要注意代码结构的严谨性~!!!
应用:在商城类网站购物车中,组合产品下面还有子产品,在移出组合产品的时候需要同时将子产品移出,可以通过设置一个class来获取一个集合,each遍历移出每一个达到效果。