jquery 课堂案例

Original 2019-06-03 18:31:16 237
abstract:<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.js"></script>
<style>
a{
display: block;
float: left;
margin: 50px;
width: 100px;
height: 100px;
line-height: 100px;
text-decoration: none;
text-align: center;
color: #fff;
border-radius: 50%;
}
</style>
</head>
<body>
<a href="">1</a>
<a href="">2</a>
<a href="">3</a>
<a href="">4</a>
<script>
// 改变标签的背景颜色
function changeBg(tag){
var len = document.getElementsByTagName(tag).length;
for(var i=0;i<len;i++){
document.getElementsByTagName(tag)[i].style.background = 'rgb(' +Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256)+')';
}
}

$(function(){
changeBg('a');
$('a').hover(function(){
// 获取当前的背景色
$bg = $(this).css('background-color');
$(this).css('box-shadow','0px 0px 20px '+$bg);
$(this).css('border-radius', '20px');
},function(){
$(this).css('box-shadow','none');
$(this).css('border-radius', '50%');
})
})
</script>
</body>
</html>


Correcting teacher:查无此人Correction time:2019-06-04 09:26:54
Teacher's summary:完成的不错。jq比js简单很多,多练习。继续加油。

Release Notes

Popular Entries