选择器 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");
jQuery day02
猜你喜欢
转载自www.cnblogs.com/gt-Lee/p/10051315.html
今日推荐
周排行