<!-- 把下面代码加到<body>区域中 -->
<SCRIPT LANGUAGE="JavaScript">
<!-- Começar
<!--
função encontrarRoots() {
var ff = documento.forms[
"quad"];
var a = ff.elements[
"a"].valor;
var b = ff.elementos[
"b"].valor;
var c = ff.elementos[
"c"].valor;
if(a.comprimento == 0 || a == "0") {
alert("O coeficiente de x^2 deve ser um número diferente de zero.");
retornar;
}
var addOf = -1*b;
var raizOf = b*b - 4*a*c;
var denomOf = 2*a;
ff.elementos[
"ser"].valor = addOf;
ff.elementos[
"raiz"].valor = rootOf;
ff.elementos[
"denom"].valor = denomOf;
var firstDivide = addOf /denomOf;
if(raizOf == 0) {
ff.elementos[
"x1"].valor = primeiroDividir;
ff.elementos[
"x2"].valor = "";
} else if(rootOf < 0) {
rootOf *= -1;
rootOf = Math.sqrt(rootOf);
rootOf /= denomOf;
ff.elementos[
"x1"].valor = primeiroDivide + " + i" + rootOf;
ff.elementos[
"x2"].value = firstDivide + " - i" + rootOf;
} senão if(rootOf > 0) {
rootOf = Math.sqrt(rootOf);
rootOf /= denomOf;
ff.elementos[
"x1"].value = (firstDivide + rootOf);
ff.elementos[
"x2"].value = (firstDivide - rootOf);
}
}
//-->
// Fim -->
</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" valor="18" class="num" tamanho=2>
</p><p>
<input type="button" value="计算" onclick="findRoots();">
</p>
<p>
<table cellpadding=0 cellpacing=0 border=0>
<tr>
<td rowspan=3 alinhar="direita">
x<sub>1</sub>, x<sub>2</sub> =
</td>
<td alinhar="centro">
<input name="be" class="num" size=2> + root(<input name="root" class="num" size=3>)
</td>
<td rowspan=3>
=
</td>
<td rowspan=3 alinhar="esquerda">
<input name="x1" class="num" size="25"><br><input name="x2" class="num" size="25">
</td>
</tr>
<tr>
<td>
<h largura="100%" tamanho=1>
</td>
</tr>
<tr>
<td alinhar="centro">
<input name="denom" class="num" tamanho=3>
</td></tr></table></p>
</form>