博客列表 >第十三节课:1.jQuyerr的工作原理

第十三节课:1.jQuyerr的工作原理

黄忠倚的博客
黄忠倚的博客原创
2018年04月04日 17:45:23595浏览

实例

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>1.jQuyerr的工作原理</title>
		<style type="text/css">
		ul {
			margin: 30px;
			padding:10px;
			overflow: hidden;
		}
		li {
			list-style-type: none;
			width: 40px;
			height: 40px;
			margin-left: 10px;
			background-color: lightskyblue;
			text-align: center;
			line-height: 40px;
			font-size: 1.2em;
			font-weight: bolder;
			float: left;
			border-radius: 50px;
			box-shadow: 2px 2px 2px #808080;
		}
		/*将对一个小球背景色换成绿色*/
		/*li:first-child {
			background-color: lightgreen;
		}
		li:nth-child(4) {
			background-color: orangered;
			color: white;
		}*/
		/*li:nth-child(4) ~ * {
			background-color: lightgreen;
		}*/
		</style>
</head>
<body>
	<ul>
		<li>1</li>
		<li>2</li>
		<li>3</li>
		<li>4</li>
		<li>5</li>
		<li>6</li>
		<li>7</li>
		<li>8</li>
		<li>9</li>
		<li>10</li>
	</ul>
</body>
</html>
<script type="text/javascript">
	// document.getElementsByTagName('li')[0]
	// li.style.backgroundColor = 'lightgreen'
	 
	// querySelector()
	// 只会返回满足条件的一个元素,但仅返回第一个
	// var li = document.querySelector('li:first-child')
	// li.style.backgroundColor = 'lightgreen'
	
	// var li = document.querySelector('li:nth-child')
	// li.style.backgroundColor = 'orangered' 
	// li.style.color = 'white'
	
	// var li = document.querySelector('li:nth-child(4) ~ *')
	// li.style.backgroundColor = 'lightgreen'
	
	//querySelectorAll ()
	// var li = document.querySelectorAll('li:nth-child(4) ~ *')
	// alert(li.length)
	// for (var i=0;i<li.length;i++){
	// 	li[i].style.backgroundColor = 'lightgreen'
	// }
	
</script>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>

<script type="text/javascript">
		$('li:nth-child(4)~*').css('background-color','lightgreen')
</script>

运行实例 »

点击 "运行实例" 按钮查看在线实例


声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议