JSLite - 过滤

2018-12-07 00:36 更新

如有疑问欢迎到这些地方交流,欢迎加入JSLite.io组织团伙共同开发!

segmentfault社区 | 官方网站 | 官方文档-更详细 | Issues

filter

筛选出与指定表达式匹配的元素集合。

filter(selector)

filter(function(index){ ... }) 筛选出与 指定表达式匹配的元素集合。

$("div").filter("#box") //⇒ self 在所有的div对象中选择器为 #box 的过滤出来。




$("#select option").filter(function(idx){
    console.log(this.selected)
    return this.selected
})
//上面这种方法跟 not(function(index){ ... })  是一样的

not

not(selector) ⇒ collection

not(collection) ⇒ collection

not(function(index){ ... }) ⇒ collection

筛选出与 指定表达式匹配的元素集合。它的作用刚好与 filter 相反,返回。

$("#select option").not(function(idx){
    console.log(this.selected)
    return this.selected
})
//⇒ [哈哈3]
$("input").not("#input") //⇒ 返回除去 匹配到的#input


$('input').not(function(){
    console.log(this.type)
    return this.type=="text"
})
以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号