当前位置: 移动技术网 > IT编程>开发语言>Jquery > jQuery day02

jQuery day02

2018年12月03日  | 移动技术网IT编程  | 我要评论
选择器

id选择器 $("#")
$("#btn").click(function(){
    this.value = "123";
    $(this).val("345");
});

标签选择器 $("xx")

$(function(){
    $("p").text("en");
});        
.text()方法 == innertext
对象.text()获取
对象.text(value)   
隐式迭代 本身没有循环操作,jq内部帮我们循环


类选择器 $(".xx")
$("#btn").click(function(){
    $(".cls").css("backgroundcolor","pink");
});

交集选择器
$("#btn").click(function(){
    $("p.cls").css("backgroundcolor","pink");
});

并列选择器
$("#btn").click(function(){
    $("#btn,div.cls,p.cls,ul").css("backgroundcolor","green");
});


层级选择器
$("ul span").css({"backgroundcolor":"pink"});    
$("ul>span").css({"backgroundcolor":"red"}); 
$("ul~span").css({"backgroundcolor":"red"}); 获取后面的兄弟元素
$("ul+span").css({"backgroundcolor":"red"}); 获取直接相邻的兄弟元素


索引选择器
:eq(index)
:lt(index)
:gt(index)
   $("ul>li:eq(3)").css("background","red");
 $("ul>li:lt(3)").css("background","red");
 $("ul>li:gt(3)").css("background","red");
 $("ul>li:gt(5):lt(3)").css("background","red");

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网