fmpq.com
源代码:
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Fmpq教程(fmpq.com)</title> <style> .siblings *{ display: block; border: 2px solid lightgrey; color: lightgrey; padding: 5px; margin: 15px; } </style> <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"> </script> <script> $(document).ready(function(){ $("h2").prevAll(".1,.2,.3").css({"color":"red","border":"2px solid red"}); }); </script> </head> <body> <div style="width:500px;" class="siblings"> <h3 class="3">h3 类名为 "3"</h3> <span>span</span> <span class="2">span 类名为 "2"</span> <span class="2">span 类名为 "2"</span> <p>p</p> <p class="1">p 类名为 "1"</p> <p>p</p> <h3>h3</h3> <h2>h2</h2> <span>span</span> <p>p</p> </div> <p>在这个例子中,我们返回h2的前一个兄弟节点中类名称为“1”,“2”和“3”的所有元素。</p> </body> </html>
运行结果