jQuery.uniqueSort()方法

jQuery 教程 · 2019-03-29 12:17:11

实例

从数组中删除重复的div元素

<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.uniqueSort( divs );$.uniqueSort(document.getElementsByTagName("div")); $( "div:eq(2)" ).text( "重排序后有 " + divs.length + " 个元素" ) .css( "color", "red" ); })
</script>

定义和用法

$.uniqueSort() 函数通过搜索的数组对象,排序数组,并移除任何重复的节点。

注意:两个不同的节点具有相同的属性是被认为不重复的。此功能只适用于普通的 JavaScript DOM 元素的数组,主要是 jQuery 内部使用。
在jQuery 3.0之前, 这个方法叫做 jQuery.unique()。

语法

$.uniqueSort(array)

参数 描述
array Array类型 指定的DOM元素数组。

点击查看所有 jQuery 教程 文章: https://www.codercto.com/courses/l/35.html

查看所有标签

Head First Mobile Web

Head First Mobile Web

Lyza Danger Gardner、Jason Grigsby / O'Reilly Media / 2011-12 / $ 50.84

Despite the huge number of mobile devices and apps in use today, your business still needs a website. You just need it to be mobile. Head First Mobile Web walks you through the process of making a con......一起来看看 《Head First Mobile Web》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

在线进制转换器
在线进制转换器

各进制数互转换器

随机密码生成器
随机密码生成器

多种字符组合密码