一个javascript问题 [英] a javascript problem

查看:52
本文介绍了一个javascript问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在IE中,这个适用于日期的javascript cod完美无缺,例如:

25.12.2004。但在Firefox或Natescape等其他互联网浏览器中,它是b / b
写的25.12.104。

可以让enybody帮助我。祝大家圣诞快乐!


这里是代码


myvar = new Date();

月=(myvar.getMonth()+ 1)

年=(myvar.getYear())

if(月== 1){WordMonth =" 1" ;}

if(月== 2){WordMonth =" 2" ;;}

if(Month == 3){WordMonth =" 3";}

if(Month == 4){WordMonth =" 4";}

if(Month == 5){WordMonth =" 5" ;;}

if(Month == 6){WordMonth =" 6";}

if(Month == 7){WordMonth =" 7";}

if(Month == 8){WordMonth =" 8";}

if(Month == 9){WordMonth =" 9";}

if(Month == 10){WordMonth =" 10";}

if(Month == 11){WordMonth =" 11";}

if(Month == 12){WordMonth =" 12";}

document.write(myvar.getDate()+"。" + WordMonth +"。" + Year + "。");

解决方
于星期六,2004年12月25日1点01分24秒0100,新< TI **** @ net4u.hr>写道:

在IE中这个日期的javascript鳕鱼工作完美,例如:
25.12.2004。但在Firefox或Natescape等其他互联网浏览器中,它写了25.12.104。


根据ECMAScript规范,getYear方法应该是

来返回当前年份减去1900. IE没有遵循这个。改为使用

getFullYear方法。


[snip]

myvar = new Date();
月= (myvar.getMonth()+ 1)
年=(myvar.getYear())
if(月== 1){WordMonth =" 1" ;;}
if(Month = = 2){WordMonth =" 2";}
if(Month == 3){WordMonth =" 3" ;;}
if(Month == 4){WordMonth =" 4" ;}
if(Month == 5){WordMonth =" 5";}
if(Month == 6){WordMonth =" 6" ;;}
if(Month = = 7){WordMonth =" 7" ;;}
if(Month == 8){WordMonth =" 8" ;;}
if(Month == 9){WordMonth =" 9" ;}
if(月== 10){WordMonth =" 10" ;;}
if(Month == 11){WordMonth =" 11" ;;}
if(Month = = 12){WordMonth =" 12" ;;}
document.write(myvar.getDate()+"。" + WordMonth +"。" + Year +"。");




这样会更简单:


var now = new Date();

document.write(now.getDate()+''。''+(now.getMonth()+ 1)+''。''

+ now.getFullYear());


将自动转换为字符串。但是,如果你期望来自其他

国家的访客,你应该

避免使用dd / mm / yyyy等模糊格式。


Mike


-

Michael Winter

替换.invalid与.uk通过电子邮件回复。


2004年12月25日星期六00:21:15 GMT,Michael Winter

< M.******@blueyonder.co.invalid>写道:

2004年12月25日星期六01:01:24 +0100,neo< ti **** @ net4u.hr>写道:

在IE中这个日期的javascript鳕鱼工作完美,例如:
25.12.2004。但是在Firefox或Natescape等其他互联网浏览器中,它写了25.12.104。



根据ECMAScript规范,getYear方法应该返回当前年份减去1900年。




这不是一个规格,它只是一个建议,如果它实施,

也没有实际的要求,最好忘记getYear如果你

可以,如果没有看到常见问题解答链接到John Stocktons博士页面。


吉姆。


neo写道:

在IE中这个日期的javascript鳕鱼完美无缺,例如:
25.12.2004 。但是在Firefox或Natescape等其他互联网观众中,它写了25.12.104。
可以帮助我。祝大家圣诞快乐!

这里是代码




d = new Date();

文件.write(d.getDate()+"。" +(d.getMonth()+ 1)+"。" + d.getFullYear());


米克


In IE this javascript cod for Date works perfectly, for a eksample:
25.12.2004. but in other Internet Viewers like Firefox or Natescape, it
writes 25.12.104.
Can enybody help me. And Happy Christmas to you all!

here is the code

myvar = new Date();
Month = (myvar.getMonth() + 1)
Year = (myvar.getYear())
if (Month == 1) {WordMonth = "1";}
if (Month == 2) {WordMonth = "2";}
if (Month == 3) {WordMonth = "3";}
if (Month == 4) {WordMonth = "4";}
if (Month == 5) {WordMonth = "5";}
if (Month == 6) {WordMonth = "6";}
if (Month == 7) {WordMonth = "7";}
if (Month == 8) {WordMonth = "8";}
if (Month == 9) {WordMonth = "9";}
if (Month == 10) {WordMonth = "10";}
if (Month == 11) {WordMonth = "11";}
if (Month == 12) {WordMonth = "12";}
document.write(myvar.getDate()+". "+WordMonth+". "+Year+".");

解决方案

On Sat, 25 Dec 2004 01:01:24 +0100, neo <ti****@net4u.hr> wrote:

In IE this javascript cod for Date works perfectly, for a eksample:
25.12.2004. but in other Internet Viewers like Firefox or Natescape, it
writes 25.12.104.
According to the ECMAScript specification, the getYear method is supposed
to return the current year minus 1900. IE doesn''t follow this. Use the
getFullYear method instead.

[snip]
myvar = new Date();
Month = (myvar.getMonth() + 1)
Year = (myvar.getYear())
if (Month == 1) {WordMonth = "1";}
if (Month == 2) {WordMonth = "2";}
if (Month == 3) {WordMonth = "3";}
if (Month == 4) {WordMonth = "4";}
if (Month == 5) {WordMonth = "5";}
if (Month == 6) {WordMonth = "6";}
if (Month == 7) {WordMonth = "7";}
if (Month == 8) {WordMonth = "8";}
if (Month == 9) {WordMonth = "9";}
if (Month == 10) {WordMonth = "10";}
if (Month == 11) {WordMonth = "11";}
if (Month == 12) {WordMonth = "12";}
document.write(myvar.getDate()+". "+WordMonth+". "+Year+".");



This would be much simpler as:

var now = new Date();
document.write(now.getDate() + ''.'' + (now.getMonth() + 1) + ''.''
+ now.getFullYear());

The conversion to string will occur automatically. However, you should
avoid ambiguous formats like dd/mm/yyyy if you expect visitors from other
countries.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.


On Sat, 25 Dec 2004 00:21:15 GMT, "Michael Winter"
<M.******@blueyonder.co.invalid> wrote:

On Sat, 25 Dec 2004 01:01:24 +0100, neo <ti****@net4u.hr> wrote:

In IE this javascript cod for Date works perfectly, for a eksample:
25.12.2004. but in other Internet Viewers like Firefox or Natescape, it
writes 25.12.104.



According to the ECMAScript specification, the getYear method is supposed
to return the current year minus 1900.



That''s not a spec though, it''s just a suggestion if it is implemented,
there''s no actual requirement too, best to just forget getYear if you
can, if not see the FAQ for links to Dr John Stocktons pages.

Jim.


neo wrote:

In IE this javascript cod for Date works perfectly, for a eksample:
25.12.2004. but in other Internet Viewers like Firefox or Natescape, it
writes 25.12.104.
Can enybody help me. And Happy Christmas to you all!

here is the code



d=new Date();
document.write(d.getDate()+"."+(d.getMonth()+1)+". "+d.getFullYear());

Mick


这篇关于一个javascript问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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