-1
我很努力工作,我無法從任何其他有價值的資源獲得幫助。我猜主要問題是DOM格式中的變量的引用。 我的代碼就在這裏(我不共享CSS,因爲它可能不會在這個錯誤很重要)我遇到了Javascript的麻煩。它說「TypeError:document.forms.inputs undefined」
`
<script>
var a, b, c;
a = document.forms["inputs"]["deg_2"].value;
b = document.forms["inputs"]["deg_1"].value;
c = document.forms["inputs"]["deg_0"].value;
var D = b^2 - 4*a*c;
var ans1 = (-b + sqrt(D)/2*a);
var ans2 = (-b - sqrt(D)/2*a);
function result(){
document.getElementById('answer1').innerHTML = ans1;
document.getElementById('answer2').innerHTML = ans2;
}
</script>
</head>
<body>
<div class = "head">
<h1 class = "head"> Quad Root Finder </h1>
</div>
<div class = "message">
<h3 class = "message"> Hello user, I am making this Quad Root Finder as one of my starting project. </h3>
</div>
<div class = "derivative">
<form name = "inputs">
<input type="text" name = "deg_2" ></input><lable for = "x^2"> x^2 + </lable>
<input type = "text" name = "deg_1"></input><lable for = "x"> x + </lable>
<input type = "text" name = "deg_0"></input><lable for = "constant"> </lable><br><br>
<button onclick="result()"> Find Roots </button>
</form>
</div>
<p class = "answer_title">
Answer:
</p>
<div class = "answer">
<h3 id = "answer1"> </h3>
<h3 id = "answer2"> </h3>
</div>
</body>
`
您必須將所有代碼放在'result()'函數中。 – JJJ