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://codercto.com/courses/l/35.html

查看所有标签

An Introduction to Probability Theory and Its Applications

An Introduction to Probability Theory and Its Applications

William Feller / Wiley / 1991-1-1 / USD 120.00

Major changes in this edition include the substitution of probabilistic arguments for combinatorial artifices, and the addition of new sections on branching processes, Markov chains, and the De Moivre......一起来看看 《An Introduction to Probability Theory and Its Applications》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具