作业1
代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>作业1</title>
<script src="../04.jq/JQuery.js"></script>
<style>
.divclass{
width:400px;
height: 400px;
background-color: purple;
margin: auto;
}
.divclassC{
width:400px;
height: 400px;
background-color: red;
margin: auto;
}
</style>
</head>
<body>
<div id="divid" class="divclass"></div>
</body>
</html>
<script>
$("#divid").click(function(){
$(".divclass").attr('class','divclassC');
});
</script>
运行截图:
点击前
点击后
作业二
代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>作业2</title>
<style>
.divclass1{
width:400px;
height: 400px;
margin: auto;
background-image:linear-gradient(to right,red,blue);
}
.divclassC{
width:400px;
height: 400px;
margin: auto;
background-image: linear-gradient(to bottom,red,blue);
}
</style>
</head>
<body>
<div onclick="changecolor()" id="divId1" class="divclass1"></div>
</html>
<script>
var div1 = document.getElementById("divId1");
function changecolor(){
if(div1.className ="divclass1"){
div1.className ="divclassC";
}else{
div1.className ="divclass1";
}
}
</script>
运行截图:
点击前
点击后