fmpq.com
源代码:
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Fmpq教程(fmpq.com)</title> <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script> <style> div { color: blue; } </style> </head> <body> <div>document中有6个div块</div> <div></div> <div class="dup"></div> <div class="dup"></div> <div class="dup"></div> <div></div> <script> $(function () { // unique() 必须获取一个原始数组 var divs = $( "div" ).get(); // 添加 3 个div 块元素 divs = divs.concat( $( ".dup" ).get() ); $( "div:eq(1)" ).text( "重排序后有 " + divs.length + " 个元素" ); divs = jQuery.unique( divs ); $( "div:eq(2)" ).text( "重排序后有 " + divs.length + " 个元素" ) .css( "color", "red" ); }) </script> </body> </html>
运行结果