数组不工作 [英] Array not working

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

问题描述



我无法让这个数组工作。我希望将游戏列入活动结束后的

天,然后从列表中删除。

功能事件(){


var today = new Date();

var dayarray = new Array(Sun,Mon,Tue,Wed,Thu, 星期五,星期六)

var montharray = new

数组(Jan,2月,Mar,4月 ;,May,Jun,Jul,A ug,Sep,Oct,Nov,Dec

;)


document.write(''< table>'');


var hockey = new Array();


hg [11] = new Array(" 2004/01/30 23:59:59"," DES MOINES");

hg [10 ] = new Array(2004/01/31 23:59:59,CEDAR RAPIDS);

hg [9] = new Array(" 2004/02/06 23 :59:59"," SIOUX CITY");

hg [8] = new Array(" 2004/02/20 23:59:59",&quo t; RIVER CITY");

hg [7] = new Array(" 2004/02/21 23:59:59"," ST LOUIS");

hg [6] = new Array(" 2004/02/25 23:59:59"," SIOUX CITY");

hg [5] = new Array(" 2004) / 02/27 23:59:59",WATERLOO);

hg [4] = new Array(2004/02/28 23:59:59,LINCOLN ;);

hg [3] = new Array(" 2004/03/05 23:59:59"," DANVILLE");

hg [2 ] = new Array(2004/03/06 23:59:59,GREEN BAY);

hg [1] = new Array(" 2004/03/09 23 :59:59",DES MOINES);

hg [0] = new Array(" 2004/03/19 23:59:59"," LINCOLN");


for(var i = hg.length-1; i> = 0; i--)

{

var event = hg [i] [1]

var date = new Date(hg [i] [0])

var year = 1900 + date.getYear()%1900 //< AD 3800

var cdate = dayarray [date.getDay()] +"," + montharray [date.getMonth()] +"

" + date.getDate()+ QUOT; " +一年+"

if(today.getTime()< = date.getTime()){

document.write(''< tr>< td valign = top>''+ cdate +''< / td>< td> - ''+ event +

''< / td>< / tr>'');

}

}


document.write(''< / table>'');

}

解决方案

Treetop说:



我无法得到这个数组工作。我希望将比赛列入比赛后的第二天,然后从列表中删除。



您创建一个名为hockey的数组,并且永远不会使用它。

您尝试使用名为hg的数组,你从未创造过。


var hockey = new Array();

hg [11] = new Array(&2004/01) / 30 23:59:59,DES MOINES");




谢谢,它现在有效,我将曲棍球重命名为hg


有没有办法限制它运行的次数?我想将它限制为

如果可能的话显示5行。


" Lee" < RE ************** @ cox.net>在消息中写道

news:bl ********* @ drn.newsguy.com ...

Treetop说:



我不能让这个阵列工作。我希望在比赛结束后的第二天将游戏列入
,然后从列表中删除。



您创建一个名为hockey的数组,并且永远不会使用它。
您尝试使用一个名为hg的数组,这是您从未创建过的。

var hockey = new Array();

hg [11] = new Array(2004/01/30 23:59:59,DES MOINES);



Treetop说:


谢谢,它现在有效,我改名为hockey

有没有办法限制多少它运行的时间?如果可能,我想将其限制为显示5行。




var moreToShow = 5;

if(moreToShow& ;&(today.getTime()< = date.getTime())){

document.write(''< tr>< td valign = top>''

+ cdate +''< / td>< td> - ''+ event

+''< / td>< / tr>'');

moreToShow--;

}



I cannot get this array to work. I want to have the game listed until the
day after the event, then come off the list.
function events() {

var today = new Date();
var dayarray=new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat")
var montharray=new
Array("Jan","Feb","Mar","Apr","May","Jun","Jul","A ug","Sep","Oct","Nov","Dec
")

document.write(''<table>'');

var hockey=new Array();

hg[11]=new Array("2004/01/30 23:59:59","DES MOINES");
hg[10]=new Array("2004/01/31 23:59:59","CEDAR RAPIDS");
hg[9]=new Array("2004/02/06 23:59:59","SIOUX CITY");
hg[8]=new Array("2004/02/20 23:59:59","RIVER CITY");
hg[7]=new Array("2004/02/21 23:59:59","ST LOUIS");
hg[6]=new Array("2004/02/25 23:59:59","SIOUX CITY");
hg[5]=new Array("2004/02/27 23:59:59","WATERLOO");
hg[4]=new Array("2004/02/28 23:59:59","LINCOLN");
hg[3]=new Array("2004/03/05 23:59:59","DANVILLE");
hg[2]=new Array("2004/03/06 23:59:59","GREEN BAY");
hg[1]=new Array("2004/03/09 23:59:59","DES MOINES");
hg[0]=new Array("2004/03/19 23:59:59","LINCOLN");

for (var i=hg.length-1;i>=0;i--)
{
var event = hg[i][1]
var date = new Date(hg[i][0])
var year = 1900 + date.getYear()%1900 // < AD 3800
var cdate=dayarray[date.getDay()]+", "+montharray[date.getMonth()]+"
"+date.getDate()+" "+year+" "
if (today.getTime() <= date.getTime()) {
document.write(''<tr><td valign=top>'' + cdate + ''</td><td>- '' + event +
''</td></tr>'');
}
}

document.write(''</table>'');

}

解决方案

Treetop said:



I cannot get this array to work. I want to have the game listed until the
day after the event, then come off the list.

You create an array named "hockey", and never use it.
You try to use an array named "hg", that you''ve never created.

var hockey=new Array();

hg[11]=new Array("2004/01/30 23:59:59","DES MOINES");




Thanks, it works now, I renamed hockey to hg

Is there a way to limit how many times it runs? I would like to limit it to
5 lines displayed if possible.


"Lee" <RE**************@cox.net> wrote in message
news:bl*********@drn.newsguy.com...

Treetop said:



I cannot get this array to work. I want to have the game listed until theday after the event, then come off the list.


You create an array named "hockey", and never use it.
You try to use an array named "hg", that you''ve never created.

var hockey=new Array();

hg[11]=new Array("2004/01/30 23:59:59","DES MOINES");



Treetop said:


Thanks, it works now, I renamed hockey to hg

Is there a way to limit how many times it runs? I would like to limit it to
5 lines displayed if possible.



var moreToShow=5;
if (moreToShow && (today.getTime() <= date.getTime())) {
document.write(''<tr><td valign=top>''
+ cdate + ''</td><td>- '' + event
+''</td></tr>'');
moreToShow--;
}


这篇关于数组不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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