所以我爲夏季班做了這個,我得讓這個地毯計算器在「執行一個document.write來顯示結果到一個新的html頁面中顯示結果「。 (直接從作業中引用)。它說要使用document.write,並在w3上使用一些教程後掌握document.write的概念,但是當我嘗試將其應用於我的項目時,它對我的網頁沒有任何影響。HTML + Javascript document.write不能正常工作
下面是我的代碼:
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<link rel="stylesheet" href="http://www.w3.org/StyleSheets/Core/Oldstyle" type="text/css" />
<head>
<title>Tutorial Project 10</title>
</head>
<body>
<h1>Carpet Calculator</h1>
<form name = "carpet" action=" ">
</br>Enter the length of your room in feet</br><input name = "length" type = "text" />
</br>Enter the width of your room in feet</br><input name = "width" type = "text" />
</br>Typically an allowance is made for room irregularities and unavoidable waste.
</br>Enter the percent overage as an integer in the interval [0, 20]</br><input name = "overage" type = "text" />
</br></br><input name = "SqFt" type = "button" value = "Compute Square Feet " onclick = "ComputeSquareFeet()" />
</br></br><input name = "SqYd" type = "button" value = "Compute Square Yards" onclick = "ComputeSquareYards()" />
</br></br><input type = "reset" value = "Clear" />
</form>
<script type="text/javascript">
function ComputeSquareFeet()
{
var SqFt = (carpet.length.value*carpet.width.value);
carpet.SqFtResult.value = SqFt+(SqFt*(carpet.overage.value/100));
document.write(SqFtResult);
}
function ComputeSquareYards()
{
var SqYd = ((carpet.length.value/3)*(carpet.width.value/3));
carpet.SqYdResult.value = SqYd+(SqYd*(carpet.overage.value/100));
document.write(SqYdResult);
}
</script>
</body>
</html>
頁是這樣的,用戶輸入的數據爲3盒,按下按鈕,它調用的函數,並在該函數結束,它執行文件。寫。然而,在做了一堆試驗和錯誤之後,我得出結論說我的公式正在工作,函數被調用,但document.write並不是由於某種原因。
關於我在做什麼錯的任何想法?謝謝!
編輯:我有這樣的顯示功能的結果,只是爲了確保它是工作,但一旦我切換到文件撰寫,似乎沒有什麼工作
你在頁面加載後使用document.write –
@JaromandaX那我該如何解決呢? http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_doc_write3我不明白它在這裏的做法與我的不同 – DrMoney