JQ选择器

1、基本选择器

<script>
    $(function(){
				
	  $ ("#btn1").click(function(){
		$("#one").css("background-color","pink");
	 			});
          $ ("#btn2").click(function(){
		$(".mini").css("background-color","pink");
				});
	  $("#btn3").click(function(){
		$("div").css("background-color","pink");
				});
				
	  $("#btn4").click(function(){
		$("*").css("background-color","pink");
				});
				
	  $("#btn5").click(function(){
		$("#two,.mini").css("background-color","pink");
				});
			});
</script>

2、层级选择器

<script type="text/javascript">
  $(function(){
   $("#btn1").click(function(){//选择body中所有的div元素
	$("body div").css("background-color","gold");
				});
				
   $("#btn2").click(function(){//选择body中的第一级的孩子
	$("body>div").css("background-color","gold");
				});
				
   $("#btn3").click(function(){//选择id为two的元素的下一个元素
	$("#two+div").css("background-color","gold");
				});
				
   $("#btn4").click(function(){//选择id为one的所有兄弟元素
	$("#one~div").css("background-color","gold");
				});
			});
</script>

3、基本过滤选择器

<script>
 $(function(){
  $("#btn1").click(function(){//body中第一个div元素
	$("body div:first").css("background-color","red");
				});
				
  $("#btn2").click(function(){//body中的最后一个div元素
	$("body div:last").css("background-color","red");
				});
				
  $("#btn3").click(function(){//选择body中的奇数的div
	$("body div:odd").css("background-color","red");
				});
				
  $("#btn4").click(function(){//选择body中的偶数的div
	$("body div:even").css("background-color","red");
				});
			});
</script>

4、属性选择器

<script>
  $(function(){
   $("#btn1").click(function(){//选择有id属性的div
    $("div[id]").css("background-color","red");
				});
				
   $("#btn2").click(function(){选择有id属性的值为two的div
    $("div[id='two']").css("background-color","red");
				});
				
			});
</script>

 

posted @ 2019-03-09 20:56  strawqqhat  阅读(132)  评论(0编辑  收藏  举报
#home h1{ font-size:45px; } body{ background-image: url("放你的背景图链接"); background-position: initial; background-size: cover; background-repeat: no-repeat; background-attachment: fixed; background-origin: initial; background-clip: initial; height:100%; width:100%; } #home{ opacity:0.7; } .wall{ position: fixed; top: 0; left: 0; bottom: 0; right: 0; } div#midground{ background: url("https://i.postimg.cc/PP5GtGtM/midground.png"); z-index: -1; -webkit-animation: cc 200s linear infinite; -moz-animation: cc 200s linear infinite; -o-animation: cc 200s linear infinite; animation: cc 200s linear infinite; } div#foreground{ background: url("https://i.postimg.cc/z3jZZD1B/foreground.png"); z-index: -2; -webkit-animation: cc 253s linear infinite; -o-animation: cc 253s linear infinite; -moz-animation: cc 253s linear infinite; animation: cc 253s linear infinite; } div#top{ background: url("https://i.postimg.cc/PP5GtGtM/midground.png"); z-index: -4; -webkit-animation: da 200s linear infinite; -o-animation: da 200s linear infinite; animation: da 200s linear infinite; } @-webkit-keyframes cc { from{ background-position: 0 0; transform: translateY(10px); } to{ background-position: 600% 0; } } @-o-keyframes cc { from{ background-position: 0 0; transform: translateY(10px); } to{ background-position: 600% 0; } } @-moz-keyframes cc { from{ background-position: 0 0; transform: translateY(10px); } to{ background-position: 600% 0; } } @keyframes cc { 0%{ background-position: 0 0; } 100%{ background-position: 600% 0; } } @keyframes da { 0%{ background-position: 0 0; } 100%{ background-position: 0 600%; } } @-webkit-keyframes da { 0%{ background-position: 0 0; } 100%{ background-position: 0 600%; } } @-moz-keyframes da { 0%{ background-position: 0 0; } 100%{ background-position: 0 600%; } } @-ms-keyframes da { 0%{ background-position: 0 0; } 100%{ background-position: 0 600%; } }