我很努力使这个工作。 dispatch()
函数似乎正在触发(通过警报测试),但innerHTML
行似乎不起作用。函数中的innerHTML(全局变量?)
此外,i
似乎并没有增加,尽管在onSubmit
i++
。
这里是有问题的功能:
function dispatch(passengers,i,timesArray)
{
alert('value of i is '+i);
timesArray[i]=getTime();
var avTime=getAverageTime(timesArrary);
var throughput=passengers*3600000/avTime;
if(i==0)
{
document.getElementById('output').innerHTML = 'Calculating...';
}
else
{
document.getElementById('output').innerHTML = throughput;
}
//and possibly a list (w/e)
}
这里是形式:
<form method="post" action="javascript:void(0);" name="applesForm" onSubmit="dispatch(document.applesForm.numPassengers.value, num, times);i++;">
<input type="text" name="numApples" id="numPassengers" />
<br/>
<input type="submit" name="Submit" value="Press on Dispatch!"/>
</form>
难道这是不能够从函数内部改变全局变量的问题?
或者,avTime
或throughput
线路正在使功能停止吗?
谢谢。
您的代码中包含一个错字timesSort,这将导致该函数的执行停止。错字是否出现在代码的实际副本中? –
你可以尝试通过你的函数走过'alert',看看它失败的地方。 –
谢谢,错字消失了。这个函数似乎在'timesArray [i] = getTime();'失败,',这行会不会成功改变times [num]'? – Jess