codecamp

JSLite - 过滤

如有疑问欢迎到这些地方交流,欢迎加入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"
})
JSLite - 尺寸位置
JSLite - 删除节点
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }