阿富

web前端

导航

【jquery API】选择器与筛选

                【选择器】字符串
                selector == str
//基本
#id、element、class、*、selector1,selector2,selectorN、、selector1selector2selectorN

//层级
ancestor descendant、parent > child、prev + next、prev ~ siblings

//表单
:input --- 所有的表单元素
:text、:password、:radio、:checkbox、:file、:image、:button、:reset、:submit
:disabled、:enabled
:checked --- radio checkbox option
    :selected --- option

//筛选
    //基本筛选器(左部为空时则表示*号)
    :not(selector) --- 排除
    :first --- 第一个 --- 1
    :last --- 最后一个 --- 1
    :eq(i|-i) --- 1
    :gt(i|-i)、:lt(i|-i) --- 大于、小于
    :even、:odd --- 按索引的奇偶
    :animateed --- 正在执行jq动画的元素
    :lang(xxx) --- (it)、(en)
    :root --- html --- 1
    :target --- hash --- 1
    :header --- h1~h6
    :focus --- 1

    //可见性
    :visible、:hidden

    //属性
    [attr]
    [attr=val]、[attr!=val]
    [attr^=val]、[attr*=val]、[attr$=val]
    [][][]

    //内容
    :contains(text) --- 包含有指定内容
    :has(selector) --- 包含有指定选择器
    :empty --- 内容为空
    :parent --- 内容不为空

    //子元素
    :first-child、:last-child
    :first-of-type、:last-of-type

    :nth-child(n)、nth-last-child(n)
    :nth-of-type(n)、nth-last-of-type(n)
        第一个:1
        偶数:2n || even
        奇数:2n+1 || odd

    :only-child、:only-of-type

//混淆选择器 3.0+
$.escapeSelector(selector) --- 处理类选择器或ID选择器中包含的特殊字符



                【筛选】方法
                selector == str|jq|DOM
//过滤
.eq(i|-i)
.first()、.last()
.filter(selector|function(i, el){ return true; })
.not(selector|function(i, el){ return true; })
.has(selector) --- selector中的任意一个即可满足
.slice(start, end)
.map(function(i, el){ return xxx; })

.is(selector|function(i, el){ return true; }) --- 任意为true时则为true
    .hasClass(className)

//查找
.find(selector)
.children(selector)
.parent(selector)、.parents(selector)、.parentsUntil(until-selector, selector)、.closest(selector) --- 对事件委托非常有用
.offsetParent() --- 仅对可见元素有效,否则返回html
.next(selector)、.nextAll(selector)、.nextUntil(until-selector, selector)
.prev(selector)、.prevAll(selector)、.prevUntil(until-selector, selector)
.siblings(selector)

//串联
.add(selector|htmlStr, [context]) --- 原jq不会被修改

.addBack(selector) --- $('#box').find('#sub').addBack(); //[#sub, #box]
.end() --- $('#box').find('#sub').end(); //[#box]

.contents() --- 所有子节点(包括文本、注释等),如果是iframe则是document

 

posted on 2016-08-09 23:30  阿富  阅读(173)  评论(0)    收藏  举报