我是初学者,谈到HTML编码。我正在尝试完成在线计算机课程的作业。我给我的教授发了电子邮件,但他在这项任务中没有太多帮助。我必须创建一个简单的成本计算器,允许用户为每件商品添加最多三件商品的数量和价格。按下onclick按钮后,应显示总价格。我上周有类似的任务,并且能够自己完成编码和设计。我不知道这一个。这是迄今为止的代码。如何在HTML文档中使用javascript创建简单的成本计算器
<html>
<head> <title> Name </title>
<br/> <br/>
<h2> <p style="text-indent: 22em;"> <FONT SIZE="7" <center> Easy Cost Calculator</center> </FONT SIZE> </h2>
<style type="text/css">
body {background-color:light blue;
color: blue;
font-family: rockwell;
}
</style>
</head>
<body>
<body style="background:#006400">
<form> <br/>
<center> <table border="2" cellpadding="25" cellspacing="25" bgcolor=lightgreen>
<tr>
<th> # of Items </th>
<th> Cost Per Item</th>
<th> Item Total</th> </tr>
<tr> <td> <input type="text" name="quantity1" size="20"> </td><td> <input type="text" name="cost per item1" size="20"> </td><td> <input type="text" name="item total1" readonly> </td> </tr>
<tr> <td> <input type="text" name="quantity2" size="20"> </td> <td> <input type="text" name="cost per item2" size="20"> </td> <td> <input type="text" name="item total2" readonly> </td> </tr>
<tr> <td> <input type="text" name="quantity3" size="20"> </td> <td> <input type="text" name="cost per item3" size="20"></td> <td> <input type="text" name="item total3" readonly> </td> </tr>
<tr> <center> <td> <input type="text" name="Total" readonly> </td> <td> <input type="button" value="Calculate Total" onclick='
var q1 = document.forms[0].quantity1.value;
var q2= document.forms[0].quantity2.value;
var q3= document.forms[0].quantity3.value;
var cpi1 = document.forms[0]. cost per item1.value;
var cpi2= document.forms[0]. cost per item2.value;
var cpi3= document.forms[0]. cost per item3.value;
var st11= q1*cpi1;
document.forms[0].item total1.value= st11;
var st2= q2*cpi2;
document.forms[0].item total2.value= st2;
var st3= q3*cpi3;
document.forms[0]. item total3.value= st3;
var tc =st11+st2+st3 ;
document.forms[0].total.value= tc;
'>
</button> </center> </td> </tr>
</table>
<br/> <br/>
</center>
</form>
</body>
</html>
你能不能扩大,究竟你还不明白吗? – ChaseHardin
你遇到的唯一真正的问题是名称中不能有空格,并且它们区分大小写,你应该能够找出其余的 – adeneo
你可以通过在这里包括'在你的代码中。 – ChaseHardin