<!-- 把下面代码加到<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>
</形式>