如何在html网页右上角添加时钟或者时间

如何在html网页右上角添加时钟或者时间,第1张

把这个DIV放缓高到你想放到的地方,然后修改一下样式就可以了

<style>

.time{...........................}

</style>

<div class="time">

<SCRIPT language=JavaScript>

<!--

tmpDate = new Date()

date = tmpDate.getDate()

month= tmpDate.getMonth() + 1

year= tmpDate.getYear()

document.write(year)

document.write("年")

document.write(month)

document.write("月")

document.write(date)

document.write("日 ")

myArray=new Array(6)

myArray[0]="星期日"

myArray[1]="星期一"

myArray[2]="星期二"

myArray[3]="星期三"

myArray[4]="星销慧期四"

myArray[5]="星期五"亏哪答

myArray[6]="星期六"

weekday=tmpDate.getDay()

if (weekday==0 | weekday==6)

{

document.write(myArray[weekday])

}

else

{

document.write(myArray[weekday])

}

// -->

</SCRIPT>

</div>

<script language="javascript" type="text/javascript">

var enabled = 0today = new Date()

var dayvar date

if(today.getDay()==0) day = "星期日 "

if(today.getDay()==1) day = "星期一 "

if(today.getDay()==2) day = "星期二 "

if(today.getDay()==3) day = "星期三 "

if(today.getDay()==4) day = "星期四 "

if(today.getDay()==5) day = "星期五 "

if(today.getDay()==6) day = "星期六 "

document.fgColor = " FF0072"

date1 =(today.getMonth() + 1 ) + "月" + today.getDate() + "日 "

date2 = day

document.write(date1.fontsize(2))

document.write(date2.fontsize(2))

document.write("<span id='则昌clock'></span>")

var now,hours,minutes,seconds,timeValue

function showtime(){

now = new Date()

hours = now.getHours()

minutes = now.getMinutes()

seconds = now.getSeconds()

timeValue = (hours >= 12) ? " " : " "

timeValue += hours+ ":"

timeValue += ((minutes <10) ? "0" : "孙粗扒凳毕") + minutes + ":"

添加的具体方法如下:

1、打开Dreamweaver新建一个html网页。

2、切换到代码视图,在<head></head>标签里,<title></title>标签后面输入JavaScript标签。  <script type="text/javascript"></script>

3、在script标签里定义一个time()函数

function time()

{

thistime=new Date()                                   //创建一个对象

var hours=thistime.getHours()                    //获取芦滚带时钟

var minutes=thistime.getMinutes()             //获取分钟

var seconds=thistime.getSeconds()              //获取秒钟

var years=thistime.getYear()                         //获取年

var months=thistime.getMonth()                //获取月

var days=thistime.getDay()    陪芦                      获取日

}

4、判断当时钟小于10的时候在前面加个0,例如8点零8分会显示08:08

if(eval(hours)<10)

{

hours="0"+hours

}

if(eval(minutes<10))

{

minutes="0"+minutes

}

if(seconds<10)

{

seconds="0"+seconds

5、thistime=hours+":"+minutes+":"+seconds  备派   //把时间显示顺序调整好

document.title=thistime                                //在标题显示

var timer=setTimeout("time()",1000)              //设置计时器,让时间每分每秒更新

6、在<body></body>标签加上加载触发事件

<body onload="time()">

7、按Ctrl+s保存,按F12在浏览器中浏览。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/bake/11992748.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-20
下一篇 2023-05-20

发表评论

登录后才能评论

评论列表(0条)

保存