发布网友 发布时间:2022-04-25 20:15
共4个回答
热心网友 时间:2022-04-23 09:23
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>简易购物车</title>
</head>
<script type="text/javascript" language="javascript">
function Compute()
{
var intCount=parseInt(document.getElementById("txtCount").value);
var intUnitPrice=parseInt(document.getElementById("txtUnitPrice").value);
var floatPostCharge=parseFloat(document.getElementById("txtPostCharge").value);
var floatAmount=document.getElementById("txtAmount").value;
if(isNaN(intCount)){//判断是否为数字类型
intCount=0;
}
if(isNaN(intUnitPrice)){//判断是否为数字类型
intUnitPrice=0;
}
if(isNaN(floatPostCharge)){//判断是否为数字类型
floatPostCharge=0;
}
var totalPrice=intCount*intUnitPrice+floatPostCharge;//总额:件数*单价+运费
document.getElementById("txtAmount").value=totalPrice;
}
</script>
<body>
<table width="432" height="185" border="1" bgcolor="#FF99FF">
<tr>
<td height="36" colspan="5" align="center">
<b>简易购物车 </b>
</td>
</tr>
<tr align="center">
<td width="71" height="67">
商品名称
</td>
<td width="71">
数量(件)
</td>
<td width="71">
单价(美元)
</td>
<td width="71">
运费(美元)
</td>
<td width="114">
<input type="button" value="合计" name="btnCompute" id="btnCompute"
onClick="Compute()" />
</td>
</tr>
<tr align="center">
<td height="69">
跑跑道具
</td>
<td>
<input id="txtCount" name="txtCount" type="text" width="50px" />
</td>
<td>
<input type="text" style="width:50px" id="txtUnitPrice"
name="txtUnitPrice" />
</td>
<td>
<input type="text" style="width:50px" id="txtPostCharge"
name="txtPostCharge" />
</td>
<td>
<input type="text" style="width:50px" id="txtAmount"
name="txtAmount" readonly="true" />
美元
</td>
</tr>
</table>
</body>
</html>
热心网友 时间:2022-04-23 10:41
js方法最后有问题
var floatAmount=document.getElementById("txtAmount").value;
floatAmount="2";
这里如果要为txtAmount赋值的话不能这样接收,需要改为:
document.getElementById("txtAmount").value = "2";
但你这里并没有编写任何计算,如果要算的话把计算式直接替换掉这个2就行了
热心网友 时间:2022-04-23 12:16
var floatAmount=document.getElementById("txtAmount").value;
floatAmount="2";
把这两句用下面一句替换一下就可以了:
document.getElementById("txtAmount").value=2
热心网友 时间:2022-04-23 14:07
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<script type="text/javascript" language="javascript">
function Compute()
{
var intCount=parseInt(document.getElementById("txtCount").value);
var intUnitPrice=parseInt(document.getElementById("txtUnitPrice").value);
var floatPostCharge=parseFloat(document.getElementById("txtPostCharge").value);
var floatAmount=intCount*intUnitPrice+floatPostCharge;//****
document.getElementById("txtAmount").value=floatAmount;//**
}
</script>
<body>
<table width="432" height="185" border="1" bgcolor="#FF99FF" >
<tr>
<td height="36" colspan="5" align="center"><b>简易购物车 </b></td>
</tr>
<tr align="center">
<td width="71" height="67">商品名称</td>
<td width="71">数量(件)</td>
<td width="71">单价(美元)</td>
<td width="71">运费(美元)</td>
<td width="114"><input type="button" value="合计" name="btnCompute" id="btnCompute" onClick="Compute()" /> </td>
</tr>
<tr align="center">
<td height="69">跑跑道具</td>
<td><input id="txtCount" name="txtCount" type="text" width="50px" /> </td>
<td><input type="text" style="width:50px" id="txtUnitPrice" name="txtUnitPrice" /> </td>
<td><input type="text" style="width:50px" id="txtPostCharge" name="txtPostCharge" /> </td>
<td><input type="text" style="width:50px" id="txtAmount" name="txtAmount" readonly="true" />
美元 </td>
</tr>
</table>
</body>
</html>
太粗心