<!-- 次の代コードを <body> 領域に追加します -->
<スクリプト言語="JavaScript">
<!-- 開始
<!--
関数 findRoots() {
var ff = document.forms[
「クワッド」];
var a = ff.elements[
"a"].value;
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 = firstDivide;
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;
else if(rootOf > 0) {
rootOf = Math.sqrt(rootOf);
rootOf /= denomOf;
ff.要素[
"x1"].value = (firstDivide + rootOf);
ff.要素[
"x2"].value = (firstDivide - rootOf);
}
}
//-->
// 終了 -->
</script>
<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 +
<input name="c" value="18" class="num" size=2>
</p><p>
<input type="button" value="计算" onclick="findRoots();">
</p>
<p>
<テーブル cellpadding=0 cellpacing=0 border=0>
<tr>
<td rowspan=3 align="right">
x<sub>1</sub>、x<sub>2</sub> =
</td>
<td align="center">
<input name="be" class="num" size=2> + root(<input name="root" class="num" size=3>)
</td>
<td rowspan=3>
=
</td>
<td rowspan=3 align="left">
<input name="x1" class="num" size="25"><br><input name="x2" class="num" size="25">
</td>
</tr>
<tr>
<td>
<hr width="100%" size=1>
</td>
</tr>
<tr>
<td align="center">
<input name="denom" class="num" size=3>
</td></tr></table></p>
</form>