Jquery 选择器

在线API
http://tool.oschina.net/apidocs/apidoc?api=jquery

-----------body onload-------------
$(fn)
是$(document).ready(fn)的简写
-----------基础选择器-------------
$()函数
传入的都是字符串,jquery内部进行正则表达式匹配
//id选择器
$("#id")
//class选择器
$(".class")
//标签选择器
$("div")
//选中所有
$("*")
//多选
$("span,.class")
--------关系过滤----------
都选择了两次
//选中子孙
$("body div")
//选中孩子
$("body>div")
//选中下一个弟弟
$(".two+div")
//选中所有弟弟
$(".two~*")
--------索引过滤-----------
//第一个
$("div:first").css("background-color","bisque")
//最后一个
$("div:last").css("background-color","cadetblue")
//偶数
$("div:even").css("background-color","#000000")
//奇数
$("div:odd").css("background-color","coral")
//索引=
$("div:eq(1)").css("background-color","aqua")
//>
$("div:gt(4)").css("background-color","red")
//<
$("div:lt(4)").css("background-color","darkgrey")
//not 参数为选择器
$("div:not(:first,:last)").css("background-color","azure")
---------索引过滤强化版-------------
//所有ul下的第一个li
$("ul>li:first-child").css("background-color", "aquamarine")

//从参数1开始,所有ul下的第n个li
$("ul>li:nth-child(2)").css("background-color","cadetblue")

//从参数1开始,所有ul下的所有3的倍数的li
$("ul>li:nth-child(3n)").css("background-color","cadetblue")
-------------内容过滤--------------
//不含节点,文本
$("div:empty").css("background-color","aquamarine")
//所有子孙含有该文本的节点
$("div:contains('11')").css("background-color","#000000")
//所有子孙含有该节点的节点
$("div:has(a)").css("background-color","red")
-----------属性过滤-----------
$("input[type='button']").click(function() {
    if($("input[type='password']:first").val() == $("input[type='password']:last").val()) {
        //id以cb开头(正则表达式的符号)
        console.info($("input[id^='cb']"))
        //多个条件过滤
        console.info($("input[id^='cb'][name='aihao']"))
    } else {
        alert("两次密码不相同")
    }
})
---------表单过滤(属性过滤专业版)---------
type属性:
:input 
:text 
:password 
:radio 
:checkbox 
:submit 
:image 
:reset 
:button 
:file 
:hidden 
其他属性:
:enabled 
:disabled 
:checked 
:selected 
---------节点的显示与隐藏-----------
$("ul:gt(1)").css("display", "none")
$("button").click(function() {
    if($(this).text() == "显示") {
        $(":hidden").show()
        $(this).text("隐藏")
    }else{
        $("ul:gt(1)").hide()
        $(this).text("显示")
    }
})
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值