這是我的代碼:「XML解析錯誤:沒有很好地形成」在斐波那契數生成
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Lab 5A : Fibbonacci numbers using Javascript</title>
</head>
<body>
<h1>Fibonacci Number Generation</h1>
<h2>Using Javascript</h2>
<hr />
<script type="text/javascript">
var n = prompt("Enter the number of terms : ", "") ;
var fib0 = 0, fib1 = 1;
var i;
var tmp ;
for (i=2; i<=n; i++)
{
var tmp = fib0;
fib0 = fib1;
fib1 = tmp + fib1;
}
document.write(n > 0 ? fib1 : 0);
</script>
</body>
</html>
我收到以下錯誤:
XML Parsing Error: not well-formed Location: file:///C:/Users/s13rw81/Desktop/Lab%20Programs/IWT%20Lab/Lab5A.xhtml
Line Number 17, Column 16:
//for (i=2; i<=n; i++)
---------------^
爲什麼你在這個年齡段使用xhtml? – epascarello
'n'是一個字符串,而不是數字 – charlietfl
https://developer.mozilla.org/en/docs/Writing_JavaScript_for_XHTML – epascarello