写的一段自动计算金额的代码,要实现的结果是在键盘输入结束的时候自动计算出金额,但是输入完没反应呢。下面是自定义的函数function stock(){
//if (form1.price.value==0)
// {alert("请输入单价!");form1.price.focus();return;}
if(isNaN(form1.price.value))
{alert("您输入的不是有效值(请输入0-9之间的数)!");form1.price.focus();return;}
form1.account.value=form1.check_time.value*form1.check_price.value; //实现自动计算金额
}下面是输入框。主要的代码。
<form action="checkout_ok.php" name="form1" method="post">
<td height="25" bgcolor="#FFFFFF" colspan="7" align="center"><?php
if($rs[price]=='小时'){
$check_time=round((time()-$rs[intime])/3600);
}else{
$check_time=1;
}?>
时间:<input type="text" name="check_time" id="check_time" readonly="readonly" value="<?php echo $check_time; ?>">小时 单价<input type="text" name="check_prcie" id="check_price" onBlur="stock()" onKeyUp="if(event.keyCode==13){stock()}"></td><!--IE用event.keyCode取回被按下的字符,Netscape/Firefox/Opera用event.which-->
</tr>
<tr><td colspan="7" bgcolor="#FFFFFF" align="center">
应付金额:<input name="account" id="account" readonly="readonly" type="text"><input type="button" value="结账">
</td></tr></form> 没反应是怎么个情况 不能调用stock()函数呢。
//if (form1.price.value==0)
// {alert("请输入单价!");form1.price.focus();return;}
if(isNaN(form1.price.value))
{alert("您输入的不是有效值(请输入0-9之间的数)!");form1.price.focus();return;}
form1.account.value=form1.check_time.value*form1.check_price.value; //实现自动计算金额
}下面是输入框。主要的代码。
<form action="checkout_ok.php" name="form1" method="post">
<td height="25" bgcolor="#FFFFFF" colspan="7" align="center"><?php
if($rs[price]=='小时'){
$check_time=round((time()-$rs[intime])/3600);
}else{
$check_time=1;
}?>
时间:<input type="text" name="check_time" id="check_time" readonly="readonly" value="<?php echo $check_time; ?>">小时 单价<input type="text" name="check_prcie" id="check_price" onBlur="stock()" onKeyUp="if(event.keyCode==13){stock()}"></td><!--IE用event.keyCode取回被按下的字符,Netscape/Firefox/Opera用event.which-->
</tr>
<tr><td colspan="7" bgcolor="#FFFFFF" align="center">
应付金额:<input name="account" id="account" readonly="readonly" type="text"><input type="button" value="结账">
</td></tr></form> 没反应是怎么个情况 不能调用stock()函数呢。
单价<input type="text" name="check_prcie" id="check_price" onBlur="stock()" onKeyUp="if(event.keyCode==13){stock()}">