jQuery.unique()方法

jQuery 教程 · 2019-03-29 11:58:02

实例

从数组中删除重复的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.unique( divs ); $( "div:eq(2)" ).text( "重排序后有 " + divs.length + " 个元素。" ) .css( "color", "red" ); }) </script>

定义和用法

$.unique() 函数用于对DOM元素数组进行排序,并移除重复的元素。

注意:1. 仅适用于DOM元素数组,不能处理字符串或者数字数组。
2. 这里的重复指的是两个元素实际上是同一个元素(通过全等"==="来判断),例如不同节点属性相同的元素不被认为重复的元素。
3. 在jQuery 3.0中,这种方法已被弃用,只是jQuery.uniqueSort()的别名。请使用该方法代替。

语法

$.unique( array )

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

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

查看所有标签

Learning Python, 5th Edition

Learning Python, 5th Edition

Mark Lutz / O'Reilly Media / 2013-7-6 / USD 64.99

If you want to write efficient, high-quality code that's easily integrated with other languages and tools, this hands-on book will help you be productive with Python quickly. Learning Python, Fifth Ed......一起来看看 《Learning Python, 5th Edition》 这本书的介绍吧!

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

Base64 编码/解码

html转js在线工具
html转js在线工具

html转js在线工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换