Answer_2
如果字段中的数字大于 10 或小于 -10,如何弹出警告框?
Javascript:
function CalculateIMSUB(Atext, Btext, form, val)
{
var A = eval(Atext);
var B = eval(Btext);
if (isNaN(A)) A = 0;
if (isNaN(B)) B = 0;
var answer = A - B;
form.Answer.value = answer;
var diff = answer - val;
if (diff == 0)
form.Answer_2.value = 'ok';
else if (diff < 0)
form.Answer_2.value = diff;
else
form.Answer_2.value = '+' + diff;
}
function calculateAll() {
var forms = document.getElementsByTagName("form");
for(var i = 0; i < forms.length; i++ ) {
CalculateIMSUB(forms[i].input_A.value, forms[i].input_B.value,forms[i], 96)
}
}
HTML:
<FORM NAME="Calculator" METHOD="GET">
<P><INPUT TYPE=TEXT NAME="input_A" SIZE=10><INPUT TYPE=TEXT NAME="input_B" SIZE=10>
<INPUT TYPE="button" VALUE="+" name="subtractbutton" onclick="CalculateIMSUB
(this.form.input_A.value, this.form.input_B.value, this.form, 96)">
<INPUT TYPE=TEXT NAME="Answer" SIZE=12><tt>96</tt><INPUT TYPE=TEXT NAME="Answer_2"
SIZE=4></P></form>
<input type="button" onclick="calculateAll()" value="Master calculation" />
首先十分感谢