由于某些原因,我的总数是* 10,我在某处犯了一些愚蠢的错误。只是为我正在构建的表单计算出一种计算方法,但是它仍然存在于最后一个元素上。
gst输入没有小数位,我现在不会过分烦恼它可以稍后添加但是从我看到它应该只是+元素和输出。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<script type="text/javascript">
function updatePrice() {
// Get the ex-GST price from its form element
var exPrice = document.getElementById("ex-gst").value;
var TPrice = document.getElementById("gst").value;
// Get the GST price
gstPrice = exPrice * 0.1;
TPrice = gstPrice + exPrice;
// Set the GST price in its form element
document.getElementById("gst").value = gstPrice;
document.getElementById("inc-gst").value = TPrice;
}
</script>
<table border=0 cellspacing=2 cellpadding=2>
<tr>
<th width="5"> </th>
<th width="264"> </th>
<th><font size="2" face="Geneva, Arial, Helvetica, sans-serif">Attendees</font></th>
</tr>
<tr>
<td align=center> </td>
<td align=right>Calculate</td>
<td align=right> <input id="ex-gst" name="ex-gst" value="0.00" size=7 maxlength=10 onChange="updatePrice()"></td>
</tr>
<tr>
<td align=center> </td>
<td align=right> 12.5% G.S.T </td>
<td align=right> <input type=text id="gst" name="gst" size=7 maxlength=10 value="0.00" onChange="updatePrice()"></td>
</tr>
<tr>
<td align=center> </td>
<td align=right>Total Payable</td>
<td align=right> $
<input name="inc-gst" id="inc-gst" type="text" value="0.00" size=7 maxlength=10 onChange="updatePrice(this.form)">
</td>
</tr>
</table>
</body>
</html>
答案 0 :(得分:0)
让它工作,只需做一些轻微的编辑
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<script type="text/javascript">
function updatePrice() {
// Get the ex-GST price from its form element
var exPrice = document.getElementById("ex-gst").value;
var gstPrice = document.getElementById("gst").value;
// Get the GST price
gstPrice = exPrice * 0.1;
var TPrice = parseInt(gstPrice) + parseInt(exPrice);
// Set the GST price in its form element
document.getElementById("gst").value = gstPrice;
document.getElementById("inc-gst").value = TPrice;
}
</script>
<table border=0 cellspacing=2 cellpadding=2>
<tr>
<th width="5"> </th>
<th width="264"> </th>
<th><font size="2" face="Geneva, Arial, Helvetica, sans-serif">Attendees</font></th>
</tr>
<tr>
<td align=center> </td>
<td align=right>Calculate</td>
<td align=right> <input id="ex-gst" name="ex-gst" value="0.00" size=7 maxlength=10 onChange="updatePrice()"></td>
</tr>
<tr>
<td align=center> </td>
<td align=right> 12.5% G.S.T </td>
<td align=right> <input type=text id="gst" name="gst" size=7 maxlength=10 value="0.00" onChange="updatePrice()"></td>
</tr>
<tr>
<td align=center> </td>
<td align=right>Total Payable</td>
<td align=right> $
<input name="inc-gst" id="inc-gst" type="text" value="0.00" size=7 maxlength=10 onChange="updatePrice(this.form)">
</td>
</tr>
</table>
</body>
</html>