前端的案例
1.html的form表单的使用
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>js的操作符</title>
</head>
<body>
<form action ="" method="get" enctype="multipart/form-data">
<p><label for = "1">用户名:<input type="text" name="user" id = "1"></p>
<p>密 码:<input type="password" name="psw"></p>
<p>
性 别:
<input type="radio" name="lalal1" value="male"> 男
<input type="radio" name="lalal2" value="female"> 女
<input type="radio" name="lalal3" value="secret"> 保密
</p>
<p>
爱 好:
<input type="checkbox" name="hobby" value="singing"> 唱歌
<input type="checkbox" name="hobby" value="dance"> 跳舞
<input type="checkbox" name = "hobby" value="rap"> rap
</p>
<p>
上传文件:<input type="file">
</p>
<p>
地 址:
<select name="attr" id="">
<optgroup label="黑龙江省">
<option value="jms" selected>佳木斯</option>
<option value="hr">哈尔滨</option>
</optgroup>
<optgroup label="吉林省">
<option value="cc">长春</option>
<option value="sy">松原</option>
</optgroup>
</select>
</p>
<p>
个人简介:
<textarea name="profile" rows = "10" cols = "20"></textarea>
<p>
<input type="submit" value="提交">
<input type="reset" value="重置">
</p>
</form>
</body>
</html>
2.背景样式
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>背景样式</title>
<style>
*{
margin: 0;
padding: 0;
} /*使你的页面能全部的契合浏览器*/
.top{
width: 100%;
height: 64px;
background: black;
}
.top .menu{
width: 1200px;
height: 100%;
background: #6fa026;
margin: 0 auto;
} /*这里的top后面记得加空格因为这是后代选择器,有个特别需要记得的点就是margin:0 auto是使子标签居中*/
.middle{
width: 100%;
height: 500px;
background: wheat;
}
.middle .content{
width:1200px;
height:100%;
background: #3d3c75;
margin:0 auto;
}
.bottom1{
width: 100%;
height: 100px;
background: #775522;
}
.bottom1 .bot-top1{
width: 1200px;
height: 100%;
background: gold;
margin:0 auto;
}
.bottom2{
width: 100%;
height: 60px;
background: black;
}
.bottom2 .bot-top2{
width: 1200px;
height:100%;
background: coral;
margin:0 auto;
}
</style>
</head>
<body>
<div class="top">
<div class="menu"></div>
</div>
<div class="middle">
<div class="content"></div>
</div>
<div class="bottom1">
<div class="bot-top1"></div>
</div>
<div class="bottom2">
<div class="bot-top2"></div>
</div>
</body>
</html>
这里为了截图方便而且能解全面所以我用的500px,如果调成800px会更好看一些。
3.静态轮播图
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>静态轮播图</title>
<style>
*{
margin: 0;
padding: 0;
}
ul{
list-style: none;
/*text-align: center;*/
}
.top{
width: 100%;
height: 64px;
background: black;
}
.top .menu{
width: 1200px;
height: 100%;
background: #6fa026;
margin: 0 auto;
} /*这里的top后面记得加空格因为这是后代选择器,有个特别需要记得的点就是margin:0 auto是使子标签居中*/
.middle{
width: 100%;
height: 800px;
background: wheat;
}
.middle .content{
width:1200px;
height:100%;
background:white;
margin:0 auto;
}
.middle .content .con-left{
height:100%;
width: 850px;
background: darkviolet;
float: left;
}
.middle .content .con-left .banner{
height: 200px;
width:850px;
background: cyan;
position: relative;
}
.middle .content .con-left .banner .cir{
/*height: 17px;*/
/*width: 118px;*/
/*background: #754e22;*/
bottom: 20px;
position: absolute;
left: 50%;
margin-left: -59px;
}
.middle .content .con-left .banner .cir li{
height: 15px;
width: 15px;
float: left;
border: 1px solid red;
margin-left: 10px;
border-radius: 50%;
/*position: absolute;*/
}
.middle .content .con-left .banner .btn{
font-size: 50px;
color: white;
height:200px;
line-height: 200px;
}
.middle .content .con-left .banner .btn #left{
position: absolute;
left: 20px;
}
.middle .content .con-left .banner .btn #right{
position: absolute;
right: 20px;
}
.middle .content .con-left .banner img{
height: 200px;
width: 850px;
position: absolute;
}
.middle .content .con-right{
height:100%;
width: 300px;
background: #754e22;
float: right;
}
.bottom1{
width: 100%;
height: 100px;
background: #775522;
}
.bottom1 .bot-top1{
width: 1200px;
height: 100%;
background: gold;
margin:0 auto;
}
.bottom2{
width: 100%;
height: 60px;
background: black;
}
.bottom2 .bot-top2{
width: 1200px;
height:100%;
background: coral;
margin:0 auto;
}
</style>
</head>
<body>
<div class="top">
<div class="menu"></div>
</div>
<div class="middle">
<div class="content">
<div class="con-left">
<div class="banner">
<ul class="pic">
<li><img src="D:\pathfinder\untitled1\8.jpeg" alt=""></li>
<li><img src="D:\pathfinder\untitled1\7.png" alt=""></li>
<li><img src="D:\pathfinder\untitled1\9.png" alt=""></li>
<li><img src="D:\pathfinder\untitled1\4.jpeg" alt=""></li>
</ul>
<ul class="btn">
<li id="left"><</li>
<li id="right">></li>
</ul>
<ul class="cir">
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
</div>
<div class="con-right"></div>
</div>
</div>
<div class="bottom1">
<div class="bot-top1"></div>
</div>
<div class="bottom2">
<div class="bot-top2"></div>
</div>
</body>
</html>
这个暂时还不能导入功能,动态的轮播图可以实现点击的事件。
4.点击事件
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>js事件操作</title>
<style>
div{
width: 300px;
height: 300px;
background: cyan;
text-align: center;
line-height: 300px;
}
.wo{
font-size: 30px;
font-family: 华文楷体;
}
.set{
width: 80px;
height: 30px;
background: gold;
margin-left: 20px;
}
</style>
</head>
<body>
<p>
<label for="attr">样 式:</label>
<input type="text" id="attr" placeholder="请输入css样式">
</p>
<p>
<label for="attv">样式值:</label>
<input type="text" id="attv" placeholder="请输入样式值">
</p>
<p>
<input class="set" type="button" value="设置">
</p>
<div class="wo">我就是我</div>
<script>
var obj = document.querySelector("div");
obj.onmouseenter = function () {
obj.innerText ="我其实不是我"
};
obj.onmouseleave = function () {
obj.innerText = "我就是我"
};
var input = document.querySelectorAll("input");
input[2].onclick = function () {
var attr = input[0].value;
var attv = input[1].value;
obj.style[attr] = attv;
obj[attr] = attv;
}
</script>
</body>
</html>
这个还是很好玩的,你可以直接通过在上面填充指令,下面就可以直接出现。
5.动态轮播图
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>轮播图</title>
<style>
*{
margin: 0;
padding: 0;
}
ul{
list-style: none;
/*text-align: center;*/
}
.top{
width: 100%;
height: 64px;
background: black;
}
.top .menu{
width: 1200px;
height: 100%;
background: #6fa026;
margin: 0 auto;
} /*这里的top后面记得加空格因为这是后代选择器,有个特别需要记得的点就是margin:0 auto是使子标签居中*/
.middle{
width: 100%;
height: 800px;
background: wheat;
}
.middle .content{
width:1200px;
height:100%;
background:white;
margin:0 auto;
}
.middle .content .con-left{
height:100%;
width: 850px;
background: darkviolet;
float: left;
}
.middle .content .con-left .banner{
height: 200px;
width:850px;
background: cyan;
position: relative;
}
.middle .content .con-left .banner .cir{
/*height: 17px;*/
/*width: 118px;*/
/*background: #754e22;*/
bottom: 20px;
position: absolute;
left: 50%;
margin-left: -59px;
}
.middle .content .con-left .banner .cir li{
height: 15px;
width: 15px;
float: left;
border: 1px solid red;
margin-left: 10px;
border-radius: 50%;
cursor: pointer;
/*position: absolute;*/
}
.middle .content .con-left .banner .cir li:hover{
background: white;
}
.middle .content .con-left .banner .btn{
font-size: 50px;
color: white;
height:200px;
line-height: 200px;
display: none;
cursor: pointer;
}
.middle .content .con-left .banner:hover .btn{
display: block;
}
.middle .content .con-left .banner .btn #left{
position: absolute;
left: 20px;
}
.middle .content .con-left .banner .btn #right{
position: absolute;
right: 20px;
}
.middle .content .con-left .banner img{
height: 200px;
width: 850px;
position: absolute;
display: none;
}
.middle .content .con-left .banner .pic .show
{
display: block;
}
.middle .content .con-right{
height:100%;
width: 300px;
background: #754e22;
float: right;
}
.bottom1{
width: 100%;
height: 100px;
background: #775522;
}
.bottom1 .bot-top1{
width: 1200px;
height: 100%;
background: gold;
margin:0 auto;
}
.bottom2{
width: 100%;
height: 60px;
background: black;
}
.bottom2 .bot-top2{
width: 1200px;
height:100%;
background: coral;
margin:0 auto;
}
</style>
</head>
<body>
<div class="top">
<div class="menu"></div>
</div>
<div class="middle">
<div class="content">
<div class="con-left">
<div class="banner">
<ul class="pic">
<li><img class="show" src="D:\pathfinder\untitled1\8.jpeg" alt=""></li>
<li><img src="D:\pathfinder\untitled1\7.png" alt=""></li>
<li><img src="D:\pathfinder\untitled1\9.png" alt=""></li>
<li><img src="D:\pathfinder\untitled1\6.jpeg" alt=""></li>
</ul>
<ul class="btn">
<li id="left"><</li>
<li id="right">></li>
</ul>
<ul class="cir">
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
</div>
<div class="con-right"></div>
</div>
</div>
<div class="bottom1">
<div class="bot-top1"></div>
</div>
<div class="bottom2">
<div class="bot-top2"></div>
</div>
<script>
var obj = document.querySelectorAll(".cir li");
var pic = document.querySelectorAll(".pic img");
n = 1;
for(let i=0;i<obj.length;i++)
obj[i].onclick = function () {
for(let j=0;j<pic.length;j++)
if(i===j){
pic[j].className = "show";
n = j;
}
else{
pic[j].className = "";
}
}
var btn = document.querySelectorAll(".btn li");
btn[0].onclick = function () {
if(n>0){
pic[n].className = "";
n--;
pic[n].className = "show";
}
else {
pic[n].className = "";
n = pic.length-1;
pic[n].className = "show";
}
};
btn[1].onclick = function () {
pic[n].className = "";
n = n + 1;
// pic[n].className = "show";
if(n > pic.length-1){
n=0;
}
pic[n].className = "show";
};
function auto1() {
pic[n].className = "";
n = n + 1;
if(n > pic.length-1){
n=0;
}
pic[n].className = "show";
}
var timer = setInterval(auto1, 2000);
var banner = document.querySelector(".banner");
banner.onmouseenter = function(){
clearInterval(timer);
}
banner.onmouseleave = function () {
timer = setInterval(auto1, 2000);
}
</script>
</body>
</html>
这个是动态的轮播图。
6.自己写的巨星不易
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>my_html</title>
<style>
*{
margin: 0;
padding: 0;
}
ul{
list-style: none;
}
.top{
background: black;
height: 60px;
width: 100%;
}
.top .menu{
background: green;
width: 500px;
height: 100%;
line-height: 60px;
text-align: center;
margin: 0 auto;
font-size: 25px;
font-family: 华文仿宋;
font-weight: bolder;
}
.mid{
background: aqua;
height: 600px;
width: 100%;
}
.mid .content{
background: white;
width: 500px;
height: 100%;
margin: 0 auto;
position: relative;
/*float: left;*/
}
.mid .content .list{
position: absolute;
bottom: 20px;
left: 50%;
margin-left: -102px;
}
.mid .content .list li{
background: gold;
width: 20px;
height: 20px;
float: left;
border: 1px solid red;
margin-left: 30px;
border-radius: 50%;
cursor: pointer;
text-align: center;
line-height: 20px;
}
.mid .content .arrows{
font-size: 60px;
color: black;
height:200px;
line-height: 200px;
font-family: 华文琥珀;
cursor: pointer;
}
.mid .content .arrows #left{
position: absolute;
left: 20px;
bottom: 300px;
}
.mid .content .arrows #right{
position: absolute;
right: 20px;
bottom: 300px;
}
.mid .content img{
width: 500px;
height: 550px;
position: absolute;
display: none;
}
.mid .content .show{
display: block;
}
.bottom{
background: black;
height: 80px;
width: 100%;
}
</style>
</head>
<body>
<div class="top">
<div class="menu">
大家好,我叫毛不易
</div>
</div>
<div class="mid">
<div class="content">
<ul class="list">
<li>一</li>
<li>二</li>
<li>三</li>
</ul>
<img src="D:\pathfinder\untitled1\1.jpeg" >
<img class="show" src="D:\pathfinder\untitled1\4.jpeg">
<img src="D:\pathfinder\untitled1\6.jpeg">
<!--<img src="D:\pathfinder\untitled1\7.png">-->
<ul class="arrows">
<li id="left"><</li>
<li id="right">></li>
</ul>
</div>
</div>
<div class="bottom">
</div>
<script>
var img = document.querySelectorAll(".content img");
var list = document.querySelectorAll(".list li");
n = 1;
for(let i=0;i<list.length;i++){
list[i].onclick = function () {
for(let j=0;j<img.length;j++){
if(i===j){
img[j].className = "show";
n = j ;
}
else {
img[j].className = "";
}
}
}
}
var arrow = document.querySelectorAll(".arrows li");
arrow[0].onclick = function () {
if (n > 0) {
img[n].className = "";
n--;
img[n].className = "show";
}
else {
img[n].className = "";
n = img.length - 1;
img[n].className = "show";
}
};
arrow[1].onclick = function () {
img[n].className = "";
n = n + 1;
// pic[n].className = "show";
if(n > img.length-1){
n=0;
}
img[n].className = "show";
};
function auto1() {
img[n].className = "";
n = n + 1;
if(n > img.length-1){
n=0;
}
img[n].className = "show";
}
var timer = setInterval(auto1, 1000);
var banner = document.querySelector(".content");
banner.onmouseenter = function(){
clearInterval(timer);
}
banner.onmouseleave = function () {
timer = setInterval(auto1, 1000);
}
</script>
</body>
</html>