js实现登录页面的背景图片的随机展示

####js代码如下:

<script type="text/javascript">
		// 随机展示背景图片 
		var imgSrcs = [ "${ctx}/static/images/background/1.jpg",
				"${ctx}/static/images/background/2.jpg",
				"${ctx}/static/images/background/3.jpg",
				"${ctx}/static/images/background/4.jpg" ];
		var randomBgIndex = parseInt(Math.random() * (imgSrcs.length));

		$(document).ready(
				function() {
					$("body").css("background-image","url(" + imgSrcs[randomBgIndex] + ")");
				});
	</script>

####login.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!-- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
	<meta name="viewport" content="width=device-width, initial-scale=1"/>
	<title>Teacher-登录</title>
	
	<link rel="stylesheet" href="${ctx}/css/bootstrap.css" />
	<link rel="stylesheet" href="${ctx}/css/login.css" />
	<script type="text/javascript" src="${ctx}/js/jquery-1.11.3.min.js"></script>
	<script type="text/javascript" src="${ctx}/js/bootstrap.js"></script>

	<script type="text/javascript">
		// 随机展示背景图片 
		var imgSrcs = [ "${ctx}/images/background/1.jpg",
				"${ctx}/images/background/2.jpg",
				"${ctx}/images/background/3.jpg",
				"${ctx}/images/background/4.jpg" ];
		var randomBgIndex = parseInt(Math.random() * (imgSrcs.length));
		$(document).ready(
				function() {
					$("body").css("background-image","url(" + imgSrcs[randomBgIndex] + ")");
				});
		
		// 判断是登录账号和密码是否为空
		function checkForm(){
		    var usercode = $("#usercode").val();
		    var password = $("#password").val();
		    if(usercode=="" || password==""){
		    	$("#message").text("账号或密码不能为空!");
		        return false;
		    }  
		    return true;
		}
	</script>
</head>

<body>
	<div class="container">
		<div class="top_div"></div>

		<div class="login">
			<form action="${pageContext.request.contextPath }/login.action"
				method="post" onsubmit="return checkForm()">
				<div style="float: left; padding: 20px 10px 0px 40px;">
					<h4>
						用户登录
					</h4>
				</div>

				<div style="padding: 70px 0px 10px; position: relative;">
					<span class="glyphicon glyphicon-user" aria-hidden="true"
						style="padding: 10px 10px;"></span> <input id="usercode"
						name="usercode" class="ipt" type="text" placeholder="输入用户名" 
						value="">
				</div>
				<div style="padding: 20px 0px 10px;" position:relative;">
					<span class="glyphicon glyphicon-lock" aria-hidden="true"
						style="padding: 10px 10px;"></span> <input id="password"
						name="password" class="ipt" type="password" placeholder="输入密码"
						value="">
				</div>
				<div style="height: 5px">
					<font color="red">
							<span id="message">
								${msg }
							</span>
					</font>
				</div>
				<div
					style="height: 60px; line-height: 50px; margin-top: 30px; border-top-color: rgb(231, 231, 231); border-top-width: 1px; border-top-style: solid;">
					<div style="margin: 0px 35px 10px 45px;">
						<span style="float: center; padding: 25px 20px;">
							没有账号?<a href="${ctx }/toRegister.action" >注册</a>一个吧
						</span>
						<span style="float: right; padding: 15px 20px;"> <input
							type="submit" class="btn btn-success border" value="登录" />
						</span>
					</div>
				</div>
			</form>
		</div>
		<div class="bottom_div"></div>
	</div>
</body>
</html>

####页面显示效果

这里写图片描述

这里写图片描述

欢迎关注公众号:【皮卡战记】

在这里插入图片描述

  • 1
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值