2013-01-08 46 views
0

我已經搜索了幾天,試圖找到解決方案。我查看了php.net的信息,但它似乎與我的代碼格式不同。請有人告訴我如何進行這種計算。謝謝舍入autoSumForm值

function startCalc(){ 
    interval = setInterval("calc()",1); 
} 
function calc(){ 
    one = document.autoSumForm.firstBox.value; 
    two = document.autoSumForm.secondBox.value = ((one*20) + (110*20))/17; 
three = document.autoSumForm.thirdBox.value; 
    four = document.autoSumForm.fourthBox.value = ((three*20) + (150*20))/17; 
five = document.autoSumForm.fifthBox.value; 
    six = document.autoSumForm.sixthBox.value = ((five*20) + (250*20))/17; 
    seven = document.autoSumForm.seventhBox.value = (four*1) - (two*1); 
eight = document.autoSumForm.eigthBox.value = (six*1) - (two*1); 
} 

function stopCalc(){ 
    clearInterval(interval); 
} 
+1

這是JavaScript,而不是PHP。你問哪種語言? – Passerby

+0

對不起,我對這件事很感興趣,並且隨時瞭解情況。我想我需要JavaScript的解決方案。謝謝 – seabassvg

+0

然後看看[這個文檔](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Math#Methods)。此外,這種間隔方法對於瀏覽器來說相當「不友好」。嘗試另一種解決方案綁定這些盒子的「onchange」事件。 – Passerby

回答

0

這可能是因爲你的代碼是在Javascript中,而不是PHP。另外,這也不是跨平臺的Javascript。

你最好不要做這樣的事情:

document.forms['autoSumForm'].elements['firstBox'].value 

你可以使用一個庫如jQuery使這一點更容易和更具可讀性,但如果這是複雜的,因爲它得到,大類似jQuery的庫可能會過度殺傷。