<!-- 把下面程式碼加到<body>區域 -->
<腳本語言=“JavaScript”>
<!-- 開始
<!--
函數 findRoots() {
var ff = document.forms[
「四」];
var a = ff.elements[
“a”].值;
var b = ff.elements[
“b”].值;
var c = ff.elements[
“c”].值;
if(a.length == 0 || a == "0") {
Alert("x^2 的係數必須是非零數。");
返回;
}
var addOf = -1*b;
var rootOf = b*b - 4*a*c;
var denomOf = 2*a;
ff.元素[
"be"].value = addOf;
ff.元素[
“根”].value = rootOf;
ff.元素[
"denom"].value = denomOf;
var firstDivide = addOf / denomOf;
if(rootOf == 0) {
ff.元素[
"x1"].value = 第一個除法;
ff.元素[
"x2"].value = "";
} else if(rootOf < 0) {
rootOf *= -1;
rootOf = Math.sqrt(rootOf);
rootOf /= denomOf;
ff.元素[
"x1"].value = firstDivide + " + i" + rootOf;
ff.元素[
"x2"].value = firstDivide + " - i" + rootOf;
} 否則 if(rootOf > 0) {
rootOf = Math.sqrt(rootOf);
rootOf /= denomOf;
ff.元素[
"x1"].value = (firstDivide + rootOf);
ff.元素[
"x2"].value = (firstDivide - rootOf);
}
}
//-->
// 結束 -->
</腳本>
<form name="quad" onsubmit="return false;">
<p>請輸入相關數據
</p><p>
y = <input name="a" value="6" class="num" size=2>x<sup>2</sup> +
<input name="b" value="12" class="num" size=2>x +
<輸入名稱=“c”值=“18”類別=“num”大小= 2>
</p><p>
<input type="button" value="計算" onclick="findRoots();">
</p>
<p>
<表 cellpadding=0 cellspacing=0 border=0>
<tr>
<td rowspan=3align="右">
x<子>1</子>, x<子>2</子> =
</td>
<td對齊=“中心”>
<輸入名稱=“be”類別=“num”大小= 2> + root(<輸入名稱=“根”類別=“num”大小= 3>)
</td>
<td行跨=3>
=
</td>
<td rowspan=3 對齊=“左”>
<input name="x1" class="num" size="25"><br><input name="x2" class="num" size="25">
</td>
</tr>
<tr>
<td>
<hr寬度=“100%”尺寸=1>
</td>
</tr>
<tr>
<td對齊=“中心”>
<輸入名稱=“分”類別=“數字”大小= 3>
</td></tr></table></p>
</形式>