JSLite - 過濾

2018-12-07 00:36 更新

如有疑問歡迎到這些地方交流,歡迎加入JSLite.io組織團(tuán)伙共同開發(fā)!

segmentfault社區(qū) | 官方網(wǎng)站 | 官方文檔-更詳細(xì) | Issues

filter

篩選出與指定表達(dá)式匹配的元素集合。

filter(selector)

filter(function(index){ ... }) 篩選出與 指定表達(dá)式匹配的元素集合。

  1. $("div").filter("#box") //? self 在所有的div對象中選擇器為 #box 的過濾出來。
  2. $("#select option").filter(function(idx){
  3. console.log(this.selected)
  4. return this.selected
  5. })
  6. //上面這種方法跟 not(function(index){ ... }) 是一樣的

not

not(selector) ? collection

not(collection) ? collection

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

篩選出與 指定表達(dá)式匹配的元素集合。它的作用剛好與 filter 相反,返回。

  1. $("#select option").not(function(idx){
  2. console.log(this.selected)
  3. return this.selected
  4. })
  5. //? [哈哈3]
  6. $("input").not("#input") //? 返回除去 匹配到的#input
  7. $('input').not(function(){
  8. console.log(this.type)
  9. return this.type=="text"
  10. })
以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)