<!-- 把下面代码加到<body>区域中 -->
<BAHASA SKRIP="JavaScript">
<!-- Mulai
<!--
fungsi findRoots() {
var ff = dokumen.formulir[
"empat"];
var a = ff.elemen[
"a"].nilai;
var b = ff.elemen[
"b"].nilai;
var c = ff.elemen[
"c"].nilai;
if(a.panjang == 0 || a == "0") {
alert("Koefisien x^2 haruslah bukan nol.");
kembali;
}
var addOf = -1*b;
var rootOf = b*b - 4*a*c;
var denomOf = 2*a;
ff.elemen[
"menjadi"].value = addOf;
ff.elemen[
"root"].nilai = rootOf;
ff.elemen[
"denom"].nilai = denomOf;
var firstDivide = addOf / denomOf;
jika(rootOf == 0) {
ff.elemen[
"x1"].value = firstDivide;
ff.elemen[
"x2"].nilai = "";
} lain jika(rootOf < 0) {
rootOf *= -1;
rootOf = Matematika.sqrt(rootOf);
rootOf /= denomOf;
ff.elemen[
"x1"].value = firstDivide + " + i" + rootOf;
ff.elemen[
"x2"].value = firstDivide + " - i" + rootOf;
} lain jika(rootOf > 0) {
rootOf = Matematika.sqrt(rootOf);
rootOf /= denomOf;
ff.elemen[
"x1"].value = (pembagian pertama + rootOf);
ff.elemen[
"x2"].value = (pembagian pertama - rootOf);
}
}
//-->
// Berakhir -->
</skrip>
<form name="quad" onsubmit="return false;">
<p>请输入相关数据
</p><p>
y = <masukan nama="a" value="6" class="num" size=2>x<sup>2</sup> +
<masukan nama="b" value="12" class="num" size=2>x +
<masukan nama = "c" nilai = "18" kelas = "angka" ukuran = 2>
</p><p>
<input type="button" value="计算" onclick="findRoots();">
</p>
<p>
<tabel cellpadding=0 spasi sel=0 batas=0>
<tr>
<td rowpan=3 sejajar="kanan">
x<sub>1</sub>, x<sub>2</sub> =
</td>
<td align="tengah">
<masukan nama="be" class="num" size=2> + root(<masukan nama="root" class="num" size=3>)
</td>
<td rentang baris=3>
=
</td>
<td rowpan=3 align="kiri">
<input nama="x1" class="num" size="25"><br><input nama="x2" class="num" size="25">
</td>
</tr>
<tr>
<td>
<jam lebar="100%" ukuran=1>
</td>
</tr>
<tr>
<td align="tengah">
<masukan nama="denom" class="num" ukuran=3>
</td></tr></tabel></p>
</bentuk>