设计一个jsp页面,要求页面的颜色从周一到周日按红橙黄绿青蓝紫变化
发布网友
发布时间:2024-10-21 18:53
我来回答
共3个回答
热心网友
时间:2024-11-30 07:40
<%@page contentType="text/html;charset=utf-8" pageEncoding="utf-8" import="java.util.*"%>
<%
String[] s = new String[] { "紫7", "红1", "橙2", "黄3", "绿4", "青5", "蓝6" };
Calendar c = new GregorianCalendar();
int num = c.get(Calendar.DAY_OF_WEEK) - 1;
%>
<body style="background-color:<%=s[num]%>"></body>
把颜色代码弄好就行了.
热心网友
时间:2024-11-30 07:38
新建一个jsp文件,复制如下代码:
<%@page import="java.time.DayOfWeek"%>
<%@page import="java.time.LocalDate"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%! private String color; %>
<%
LocalDate date = LocalDate.now();
switch(date.getDayOfWeek()){
case MONDAY:
color = "red";
break;
case TUESDAY:
color = "orange";
break;
case WEDNESDAY:
color = "yellow";
break;
case THURSDAY:
color = "green";
break;
case FRIDAY:
color = "cyan";
break;
case SATURDAY:
color = "blue";
break;
case SUNDAY:
color = "violet";
break;
}
%>
<!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">
<title>Insert title here</title>
</head>
<body bgcolor="<%=color %>">
</body>
</html>
热心网友
时间:2024-11-30 07:45
步骤:利用js new Date(),获取当前时间 换算出周几,然后在命名一个数组(里面放的是星期几)
最后利用js中的 setInterval 方法重复调用自定义和函数(此函数对当前周几与数组周几进行比对,设置页面的背景颜色),,,颜色值可以去 w3c school网站查找