Web前端-网站首页和注册界面的实现

时间:2023-03-09 14:43:09
Web前端-网站首页和注册界面的实现

首页用到的知识如下:

1.bootstrap框架

2.jQuerry实现页面定时弹出广告

注册界面用到的知识:

1.bootstrap框架

2.jQuerry实现省市联动操作

3.jQuerry实现表单的校验

首页代码

 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>首页bootstrap实现</title>
<link rel="stylesheet" href="bootstrap.css" />
<script type="text/javascript" src="jquery-3.3.1.js"></script>
<script type="text/javascript" src="bootstrap.min.js" ></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.adpart{
position: fixed;
right: 0;
bottom: 0;
}
</style>
<script>
function showAd(){
$("#ad").fadeIn(2000);
}
$(function () {
$("#ad").hide();
setTimeout("showAd()",2000);
$("#shutad").click(function () {
$("#ad").fadeOut(1500)
})
})
</script>
</head>
<body>
<div class="container">
<div class="row" style="background-color: transparent;">
<div class="col-md-4 col-sm-6 col-xs-6" style="height: 50px;">
<img src="firstP_img/logo.jpg" width="80%" height="100%"/>
</div>
<div class="col-md-4 hidden-sm hidden-xs">
<img src="firstP_img/header.jpg" />
</div>
<div class="col-md-4 col-sm-6 col-xs-6 " style="line-height: 50px;height: 50px;position: absolute;right:0px">
<a href="#" class="btn">登录</a>
<a href="#" class="btn">注册</a>
<a href="#" class="btn">购物车</a>
</div>
</div> <div>
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">首页</a>
</div> <!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active"><a href="#">手机数码 <span class="sr-only">(current)</span></a></li>
<li><a href="#">电脑办公</a></li>
<li><a href="#">鞋靴箱包</a></li>
<li><a href="#">香烟酒水</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">全部分类<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">手机数码</a></li>
<li><a href="#">电脑办公</a></li>
<li><a href="#">香烟酒水</a></li>
</ul>
</li>
</ul>
<form class="navbar-form navbar-right">
<div class="form-group">
<input type="text" class="form-control" placeholder="搜索">
</div>
<button type="submit" class="btn btn-default">提交</button>
</form> </div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav> <div id="carousel-example-generic" class="carousel slide" data-ride="carousel" data-interval="1000">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-generic" data-slide-to="1"></li>
<li data-target="#carousel-example-generic" data-slide-to="2"></li>
</ol> <!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<img src="firstP_img/0.jpg" alt="...">
<div class="carousel-caption">
...
</div>
</div>
<div class="item">
<img src="firstP_img/1.jpg" alt="...">
<div class="carousel-caption">
...
</div>
</div>
<div class="item">
<img src="firstP_img/2.jpg" alt="...">
<div class="carousel-caption">
...
</div>
</div>
...
</div> <!-- Controls -->
<a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div> <div class="row">
<div class="col-md-12">
<h3>最新商品<img src="firstP_img/smtitle.jpg"></h3>
</div>
</div>
<div class="row" style="background: transparent">
<div class="col-md-2" style="height:480px;">
<img src="firstP_img/left01.jpg" height="100%" width="100%">
</div>
<div class="col-md-10">
<div class="col-md-6" style="height: 240px;">
<img src="firstP_img/middle01.jpg" width="100%" height="80%">
</div>
<div class="col-md-2" style="height: 240px;">
<img src="firstP_img/small01.jpg" width="100%" height="80%">
<p style="text-align: center">微波炉</p>
<em style="color: red">$999</em>
</div>
<div class="col-md-2" style="height: 240px;">
<img src="firstP_img/small01.jpg" width="100%" height="80%">
<p style="text-align: center">微波炉</p>
<em style="color: red">$999</em>
</div>
<div class="col-md-2" style="height: 240px;">
<img src="firstP_img/small01.jpg" width="100%" height="80%">
<p style="text-align: center">微波炉</p>
<em style="color: red">$999</em>
</div>
<div class="col-md-2" style="height: 240px;">
<img src="firstP_img/small01.jpg" width="100%" height="80%">
<p style="text-align: center">微波炉</p>
<em style="color: red">$999</em>
</div>
<div class="col-md-2" style="height: 240px;">
<img src="firstP_img/small01.jpg" width="100%" height="80%">
<p style="text-align: center">微波炉</p>
<em style="color: red">$999</em>
</div>
<div class="col-md-2" style="height: 240px;">
<img src="firstP_img/small01.jpg" width="100%" height="80%">
<p style="text-align: center">微波炉</p>
<em style="color: red">$999</em>
</div>
<div class="col-md-2" style="height: 240px;">
<img src="firstP_img/small01.jpg" width="100%" height="80%">
<p style="text-align: center">微波炉</p>
<em style="color: red">$999</em>
</div>
<div class="col-md-2" style="height: 240px;">
<img src="firstP_img/small01.jpg" width="100%" height="80%">
<p style="text-align: center">微波炉</p>
<em style="color: red">$999</em>
</div>
<div class="col-md-2" style="height: 240px;">
<img src="firstP_img/small01.jpg" width="100%" height="80%">
<p style="text-align: center">微波炉</p>
<em style="color: red">$999</em>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<img src="firstP_img/index.jpg" width="100%">
</div>
</div> <div class="row">
<div class="col-md-12">
<img src="firstP_img/footer.jpg" width="100%">
</div>
</div> <div style="text-align: center">
<a href="#" class="btn">关于我们</a>
<a href="#" class="btn">联系我们</a>
<a href="#" class="btn">招贤纳士</a>
<a href="#" class="btn">法律声明</a>
<a href="#" class="btn">友情链接</a>
<a href="# class="btn">支付方式</a>
<a href="#" class="btn">配送方式</a>
<a href="#" class="btn">服务声明</a>
<a href="#" class="btn">广告声明</a>
</div> <!-- 广告部分-->
<div class="adpart">
<div>
<a id="shutad" style="position: absolute;right: 10px;color: red">关闭</a>
</div>
<div id="ad" style="height: 250px;width: 350px">
<img src="firstP_img/ad1.jpg" width="100%" height="100%"></img>
</div>
</div>
</div> </div>
</body>
</html>

注册界面代码

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"> <title>注册界面</title>
<link rel="stylesheet" href="bootstrap.css" />
<script type="text/javascript" src="jquery-3.3.1.js"></script>
<script type="text/javascript" src="bootstrap.min.js" ></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.header{
float:left;
height:60px;
width:33%;
line-height:60px;
}
.menu{
color:white;
text-decoration:none;
line-height:50px;
}
</style>
<script type="text/javascript" src="jquery-3.3.1.js"></script> <script>
var allcities=[
["济南市","青岛市","滨州市"],
["贵林","六盘水","毕节"],
["石家庄","秦皇岛","保定"],
] $(function(){
<!--1 绑定事件-->
<!--2 获取选择的省份的值-->
<!--3 遍历对应的城市然后添加至div中-->
$("#provinces").change(function(){
var cities=allcities[this.value];
$("#cities").empty();
$(cities).each(function(i,n){
$("#cities").append("<option>"+n+"</option>");
})
}) $(".required").focus(function () {
if($(this).is("#username")){
var span=$("#span_username");
if(this.value.length < 6 ){
$(span).html("<font style='color: red;font-size: small; c'>用户名长度小于6</font>");
return false;
}
else{
$(span).html("<font class='right' style='color: grey;font-size: small'>用户名合适</font>");
return true;
}
}
else{
var span=$("#span_password");
if(this.value.length < 6 ){
$(span).html("<font style='color: red;font-size: small'>密码长度小于6</font>");
}
else{
$(span).html("<font class='right' style='color: grey;font-size: small'>密码合适</font>");
}
}
}).blur(function () {
$(this).triggerHandler("focus"); }).keyup(function () {
$(this).triggerHandler("focus");
}) $("#repassword").focus(function () {
var span=$("#span_repassword");
// if($(this).val() != $("#password").val() ){
// $(span).html("<font style='font-size:small;color: red;'>两次密码输入不一致</font>")
// }
if(this.value != $("#password").val() || $("#repassword").val().length == 0){
$(span).html("<font style='font-size:small;color: red;'>两次密码输入不一致</font>");
return false;
}
else{
$(span).html("<font class='right' style='font-size:small;color: grey;'>两次密码输入一致</font>");
return true;
} }).blur(function () {
$(this).triggerHandler("focus");
}).keyup(function () {
$(this).triggerHandler("focus");
}) $("#email").focus(function () {
var re=/^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$/;
var value=this.value;
var span=$("#span_email")
if(re.test(value)){
$(span).html("<font class='right' style='font-size:small;color: grey;'>邮箱输入合法</font>");
return true;
}
else{
$(span).html("<font style='font-size:small;color: red;'>邮箱输入不合法</font>");
return false;
}
}).blur(function () {
$(this).triggerHandler("focus");
}).keyup(function () {
$(this).triggerHandler("focus");
}) $("#submit").click(function () {
if($(".right").length == 3)
return true;
return false;
}) })
// function showCities(){
// var value=document.getElementById("provinces").value;
// var cities=allcities[value];
// var select=document.getElementById("cities")
// select.options.length=0;
// for(var i=0;i < cities.length;i++){
// var city_ele=document.createElement("option");
// var city_text=document.createTextNode(cities[i]);
// city_ele.appendChild(city_text);
// select.appendChild(city_ele);
// }
//
// }
//
//
// function showTips(id,tips){
// var sp=document.getElementById(id);
// tips="<font size='2' color='blue'>" + tips +"</font>";
// sp.innerHTML=tips;
// }
//
//
// function checkUsername(){
// var un=document.getElementById("username").value;
// var span=document.getElementById("span_username");
// if(un.length < 6){
// span.innerHTML="<font size='2' color='red'>用户名长度不足六位</font>";
// return false;
// }
// else{
// span.innerHTML="<font size='2' color='gray'>用户名可用</font>";
// return true;
// }
// }
//
//
// function checkPassword(){
// var pw=document.getElementById("password").value;
// var span=document.getElementById("span_password");
// if(pw.length < 6){
// span.innerHTML="<font size='2' color='red'>密码长度不足六位</font>";
// }
// else{
// span.innerHTML="<font size='2' color='gray'>密码可用</font>";
// return true;
// }
// }
// function checkRepassword(){
// var pw=document.getElementById("password").value;
// var rp=document.getElementById("repassword").value;
// var span=document.getElementById("span_repassword");
// if(pw != rp){
// span.innerHTML="<font size='2' color='red'>两次密码输入不一致</font>";
// }
// else{
// span.innerHTML="<font size='2' color='gray'>两次输入密码一致</font>";
// return true;
// }
// }
//
// function checkEmail(){
// var re=/^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$/;
// var email=document.getElementById("email").value;
// var span=document.getElementById("span_email");
// if(!re.test(email)){
// span.innerHTML="<font size='2' color='red'>邮箱格式不正确</font>";
// return false;
// }
// else{
// span.innerHTML="<font size='2' color='gray'>邮箱格式正确</font>";
// return true;
// }
// }
//
// function checkAll(){
// return checkUsername() && checkPassword && checkRepassword() && checkEmail();
// }
</script>
</head>
<body>
<!--第一部分-->
<div class="container">
<div class="row" style="background-color: transparent;">
<div class="col-md-4 col-sm-6 col-xs-6" style="height: 50px;">
<img src="firstP_img/logo.jpg" width="80%" height="100%"/>
</div>
<div class="col-md-4 hidden-sm hidden-xs">
<img src="firstP_img/header.jpg" />
</div>
<div class="col-md-4 col-sm-6 col-xs-6 " style="line-height: 50px;height: 50px;position: absolute;right:0px">
<a href="#" class="btn">登录</a>
<a href="#" class="btn">注册</a>
<a href="#" class="btn">购物车</a>
</div>
</div> <div>
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">首页</a>
</div> <!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active"><a href="#">手机数码 <span class="sr-only">(current)</span></a></li>
<li><a href="#">电脑办公</a></li>
<li><a href="#">鞋靴箱包</a></li>
<li><a href="#">香烟酒水</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">全部分类<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">手机数码</a></li>
<li><a href="#">电脑办公</a></li>
<li><a href="#">香烟酒水</a></li>
</ul>
</li>
</ul>
<form class="navbar-form navbar-right">
<div class="form-group">
<input type="text" class="form-control" placeholder="搜索">
</div>
<button type="submit" class="btn btn-default">提交</button>
</form> </div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav> <div style="background:url(./registP_img/regist_bg.jpg);height:480px;width:100%">
<div style="position:absolute;top:25%;left:35%;width:40%;height:360px;" >
<form class="form-horizontal" action="firstPage.html" onsubmit="return checkAll()">
<div class="form-group">
<label class="col-md-2">姓名</label>
<input type="text" id="username" class="required col-md-6">
<span id="span_username" class="col-md-4"></span>
</div>
<div class="form-group">
<label class="col-md-2">密码</label>
<input type="password" id="password" class="required col-md-6">
<span id="span_password" class="col-md-4"></span>
</div>
<div class="form-group">
<label class="col-md-2">确认密码</label>
<input type="password" id="repassword" class="col-md-6">
<span id="span_repassword" class="col-md-4"></span>
</div>
<div class="form-group">
<label class="col-md-2">性别</label>
<input type="radio" name="sex" >男
<input type="radio" name="sex">女
</div>
<div class="form-group">
<label class="col-md-2">省份</label>
<select id="provinces" >
<option value="-1">--请选择</option>
<option value="0">山东省</option>
<option value="1">贵州省</option>
<option value="2">辽宁省</option>
</select>
<select id="cities"> </select>
</div>
<div class="form-group col-md-12" >
<input style="position: absolute;left:40%" type="submit" value="注册" id="submit" >
</div>
</form>
</div>
</div> <div class="row">
<div class="col-md-12">
<img src="firstP_img/footer.jpg" width="100%">
</div>
</div> <div style="text-align: center">
<a href="#" class="btn">关于我们</a>
<a href="#" class="btn">联系我们</a>
<a href="#" class="btn">招贤纳士</a>
<a href="#" class="btn">法律声明</a>
<a href="#" class="btn">友情链接</a>
<a href="# class="btn">支付方式</a>
<a href="#" class="btn">配送方式</a>
<a href="#" class="btn">服务声明</a>
<a href="#" class="btn">广告声明</a>
</div>
</div>
</body>
</html>