<!-- 把下面代码加到<body>区域中 -->
<LANGUE SCRIPT="JavaScript">
<!-- Commencer
<!--
fonction findRoots() {
var ff = document.forms[
"quadruple"];
var a = ff.elements[
"un"].valeur ;
var b = ff.elements[
"b"].valeur ;
var c = ff.elements[
"c"].valeur ;
if(a.length == 0 || a == "0") {
alert("Le coefficient de x^2 doit être un nombre non nul.");
retour;
}
var addOf = -1*b;
var rootOf = b*b - 4*a*c;
var denomOf = 2*a;
ff.éléments[
"être"].value = addOf;
ff.éléments[
"racine"].value = rootOf;
ff.éléments[
"denom"].value = denomOf;
var firstDivide = addOf / denomOf;
si(rootOf == 0) {
ff.éléments[
"x1"].value = firstDivide;
ff.éléments[
"x2"].valeur = "";
} else if(rootOf < 0) {
rootOf *= -1;
rootOf = Math.sqrt(rootOf);
rootOf /= denomOf;
ff.éléments[
"x1"].value = firstDivide + " + i" + rootOf;
ff.éléments[
"x2"].value = firstDivide + " - i" + rootOf;
} sinon si(rootOf > 0) {
rootOf = Math.sqrt(rootOf);
rootOf /= denomOf;
ff.éléments[
"x1"].value = (firstDivide + rootOf);
ff.éléments[
"x2"].value = (firstDivide - rootOf);
}
}
//-->
// Fin -->
</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>
<table cellpadding=0 cellpacing=0 border=0>
<tr>
<td rowspan=3 align="right">
x<sub>1</sub>, x<sub>2</sub> =
</td>
<td align="centre">
<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%" taille=1>
</td>
</tr>
<tr>
<td align="centre">
<input name="denom" class="num" size=3>
</td></tr></table></p>
</form>