如何使用javascript更新网页中的数字 [英] How do update a number in a webpage with javascript

查看:102
本文介绍了如何使用javascript更新网页中的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的代码自动将最新年份放入网站的页脚。 

< script 语言 = JavaScript > copyright = new Date(); update = copyright.getFullYear(); document.write(Copyright & copy ; 2011 - + update +,保留所有权利。); < / script >

但是我想弄清楚在网页上自动更新号码会是什么样子在下面的例子中35)
如:约翰史密斯已在这里待了35年。

如果年份数根据开始日期(例如07-04-1980)更新
(因此2015年7月4日变量变为36)
。 / pre>

解决方案

尝试

  var  dt1 =  new 日期('  1980 -04-07');  var  dt2 =  new 日期( new  Date() -  dt1); document.write(  Copyright©2011-  + + document.write( 版权所有©2011  -  + dt2.getFullYear( )+  ,保留所有权利。); +   ,保留所有权利。); 


I use the code below to automatically put the latest year into the footer of a website. 

<script language="JavaScript">copyright=new Date();update=copyright.getFullYear();document.write("Copyright &copy; 2011-"+ update + ", All rights Reserved.");</script>

But I am trying to figure out what it would look like to have a number automatically update on a webpage(the number 35 in the example below)
Such as: John Smith has been here for 35 years.

Where the year number updates based on an start date(such as 07-04-1980)
(so on July 4th, 2015 the variable changes to 36)
.

解决方案

Try

var dt1 = new Date('1980-04-07');var dt2 = new Date(new Date() - dt1);document.write("Copyright © 2011-" +  + document.write("Copyright © 2011-"+ dt2.getFullYear() + ", All rights Reserved."); + ", All rights Reserved.");


这篇关于如何使用javascript更新网页中的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆