扫码关注官方订阅号
我需要给 p[class^="xxx"] 的最后一个元素定义样式,可是写 p[class^="xxx"]:last-of-type 不起作用,请问要怎么写呢?
p[class^="xxx"]
p[class^="xxx"]:last-of-type
光阴似箭催人老,日月如移越少年。
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <style type="text/css"> .d1{ width: 200px; height: 500px; background-color: #0077B0; } </style> <body> <p class="d1"> <ul> <li class="zz">li-1</li> <li class="zz">li-2</li> <li class="zz">li-3</li> <li class="zz">li-4</li> <li class="zz">li-5</li> </ul> </p> <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> <script type="text/javascript"> $(function() { $(".d1").click(function() { alert( $("li.zz:last").text() ); }) }) </script> </body> </html>
last last-child 都可以
你很可能需要了解一下last-of-type和last-child的区别
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
扫描下载App
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
last last-child 都可以
你很可能需要了解一下last-of-type和last-child的区别