Js的学习第六天

依旧是课堂的内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>一个倒计时时间的页面</title>
<script type="text/javascript" src="runtime.js"></script>
<style type="text/css">
*{
padding: 0px;
margin: 0px;
}
div{
height: 200px;
width: 200px;
border: 1px solid black;
text-align: center;
margin: auto;
margin-top: 5px;
box-shadow: 0px 0px 4px 3px blue;
}
.now1{
color: blue;
}
</style>
</head>
<body>
<!-- 这里上面的外链的js内容就是下面的注释的 -->
<!-- <script>
function runtime(){
var nowtime = new Date();
var nowyear = nowtime.getFullYear();
var nowmouth = (nowtime.getMonth())+1;
var nowday = nowtime.getDate();
return nowyear + "-" + nowmouth + "-" + nowday;
}
function running(time){
var nowdate = new Date();
var boot = new Date(time);
var mtime = (boot - nowdate) / 1000;
mtime1 = Math.abs(mtime)
var Day = parseInt(mtime1 / 60 / 60 / 24);
var hour = parseInt(mtime1 / 60 / 60 % 24);
var min = parseInt(mtime1 / 60 % 60);
var sec = parseInt(mtime1 % 60)
d = Day < 10 ? '0'+ Day : Day;
h = hour < 10 ? '0'+ hour : hour;
m = min < 10 ? '0'+ min : min;
s = sec < 10 ? '0'+ sec : sec;
str = "距离"+"<br>"+boot.getFullYear()+"年"+(boot.getMonth()+1)+"月"+boot.getDate()+"日"+boot.getHours()+"时"+boot.getMinutes()+"分"+boot.getSeconds()+"秒";
if(mtime<0){
return (str + "已经过去" + d + "天" + h + "时" + m + "分" + s + "秒");
}
else{
return (str + "还有" + d + "天" + h + "时" + m + "分" + s + "秒");
}
}
</script> -->
<div>
<h2>今天日期是</h2>
<p class="now1">
<script>
runtime();
</script>
</p>
<p>
<!-- <script>
var d = prompt("请输入日期:")
document.write(running(d))
</script> -->
<script>
var d = prompt("请输入日期:")
running(d);
</script>
</p>
</div>
</body>
</html>