XiaoHui.Net 笑汇程序员论坛
→ Web 网站开发与设计
新手请教
| bisuzhoucf | 2008-8-16 07:14 |
|
新手请教
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script language="javascript">
function clearText()
{
if (document.myform.card.value=="输入您的会员帐户")
document.myform.card.value="";
}
function check()
{
var a=document.myform.card.value;
if (a.substr(0,2)!="10" ||isNaN(a))
{
alert("格式错误,请重新输入");
document.myform.card.focus();
document.myform.card.select();
}
}
function compute()
{
var price=parseFloat(document.myform.price.value);
var number=parseFloat(docunment.myform.number.value);
document.myform.tot.value=price*number;
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<style title="text/css">
<!--
input{font-size:15px;
border:1px solid;
}
body{
background-color:#8ad3ff;
}
-->
</style>
<body>
<form name="myform">
<table width="100%" border="0">
<tr>
<td width="21%" height="47"> </td>
<td width="79%"> </td>
</tr>
<tr>
<td rowspan="6"><div align="center"><img src="123.jpg" width="250" height="542"></div></td>
<td height="81">帐号:<input type="text" name="card" id="card" onFocus="clearText()" onBLur="check()" value="输入您的会员帐户" size="15>"</td>
</tr>
<tr>
<td height="82"><hr></td>
</tr>
<tr>
<td height="81">单价:<input name="price" type="text" id="price" value="25.00" size="10" readonly>¥ </td>
</tr>
<tr>
<td height="72">数量:<input name="number" type="text" id="number" size="10" onChange="compute()">个</td>
</tr>
<tr>
<td height="86">总价:<input name="tot" type="text" id="tot" value="0.00" size="10">¥</td>
</tr>
<tr>
<td height="167" align="center"><input name="buy" type="button" id="buy" value="我要买" onClick="compute()"></td>
</tr>
</table>
</form>
</body>
</html>
为什么我点了BUY这个BUTTON没有反映.并且右下角显示网页上有错误.高手帮我看看哪里写错了 |
|
原因:
1. 你点 buy button 后, 触发 js 代码 compute(), 执行这段函数:
[code]function compute()
{
var price=parseFloat(document.myform.price.value);
var number=parseFloat(docunment.myform.number.value);
document.myform.tot.value=price*number;
}[/code]
这段函数会显示定单的总价。
2. 按下 buy 后,<form> 会被提交。你没有指定 <form> 的 action 属性,则表单提交给了自己的这个执行程序。于是这个页面相当于被重载了一次。 |
|