Blogger Information
Blog 19
fans 0
comment 0
visits 10605
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
4_3jQuery选择器
JcLi的博客
Original
415 people have browsed it

代码:

实例

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>彩虹球</title>
<style type="text/css">
ul {   
padding: 0;
margin: 0;
width: 450px;
border: 0px dashed #666;
padding: 10px 5px;
}
ul:after {  
content:'';  
display: block;  
clear:both;   
}
li { 
list-style: none; 
float: left;  
width: 40px;  
height: 40px; 
line-height: 40px; 
text-align: center; 
border-radius: 50%;
background: skyblue; 
margin-right: 5px; 
}
.bg-red {background-color: red;}
.bg-orangered {background-color: orangered;}
.bg-yellow {background-color: yellow;}
.bg-mediumseagreen {background-color: mediumseagreen;}
.bg-aqua {background-color: aqua;}
.bg-mediumblue {background-color: mediumblue;}
.bg-purple {background-color: purple;}
}
</style>
</head>
<body>
<ul>
<li id="item1">1</li>
<li class="green">2</li>
<li class="red">3</li>
<li id="item2">4</li>
<li>5<img src=""></li>
<li class="black">6</li>
<li class="blue">7</li>
</ul>
</body>
</html>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript">
    $('#item1').css('backgroundColor','red')
    $('.green').addClass('bg-orangered')
    $('li:nth-child(2) + li').addClass('bg-yellow')
    $('li:contains("4")').addClass('bg-mediumseagreen')
    $('li:has("img")').addClass('bg-aqua')
    $('li:eq(5)').addClass('bg-mediumblue')
    $('li:last-child').css('background-color','purple')
    $('li:parent').css('color','white')
</script>

运行实例 »

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


Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post