我想使用这样的倒计时脚本
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
function countdown(yr,m,d,idCountdown){
var theyear=yr;
var themonth=m;
var theday=d;
var today=new Date();
var todayy=today.getYear();
if (todayy < 1000)
todayy+=1900
var todaym=today.getMonth();
var todayd=today.getDate();
var todayh=today.getHours();
var todaymin=today.getMinutes();
var todaysec=today.getSeconds();
var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec;
var futurestring=montharray[m-1]+" "+d+", "+yr;
var dd=Date.parse(futurestring)-Date.parse(todaystring);
var dday=Math.floor(dd/(60*60*1000*24)*1);
var dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1);
var dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1);
var dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1);
var dag = "dagen";
if(dday==0&&dhour==0&&dmin==0&&dsec==1){
document.getElementById(idCountdown).value=current;
return;
}
else if(dday<=1) {
dag = 'dag';
}
document.getElementById(idCountdown).value=dday+ ' ' + dag + ' ' +dhour+" uur "+dmin+" min "+dsec+" sec";
setTimeout(function(){countdown(theyear,themonth,theday,idCountdown);}, 1000);
}
在我的 html 页面中,我将有一个这样的文本字段
<input name="aktie1" type="text" class="countdownTekst" size="27" readonly="readonly">
<input name="aktie2" type="text" class="countdownTekst" size="27" readonly="readonly">
然后我用它来使用该功能
countdown(2012,7,30, 'aktie1')
最后一个是文本字段的 ID。但是当我这样做时,我会得到一个错误
document.forms.count.idCountdown.value is undefined
如何在该函数中获取该文本字段的 id?