gpt4 book ai didi

javascript - 输入数据摘要

转载 作者:行者123 更新时间:2023-11-28 08:21:27 25 4
gpt4 key购买 nike

我想要一个摘要页面。

例如,在第 1 页中,我将要求提供客户姓名、电子邮件、订单,如 html 中所示。

点击提交后,它会链接到第 2 页,其中会弹出一个窗口,总结如下。

Customer name: xxxxxxx
Email: xxxxxxx
No of quantity ordered for item A:xx
No of quantity ordered for item B:xx
No of quantity ordered for item C:xx
Total cost:xx

HTML:

<!DOCTYPE html>
<html lang = "en">
<head>
<title> nochange.html </title>
<meta charset = "utf-8" />
<script type = "text/javascript" src = "dynValue.js" >
</script>
<style type = "text/css">
textarea {position: absolute; left: 250px; top: 0px;}
span {font-style: italic;}
p {font-weight: bold;}
td, th, table {border: thin solid black;}
</style>

</head>
<body>
<form action = "">
<p>
<span>
Customer information
</span>
<br /><br />
<label>
Name:
<input type = "text" onmouseover = "messages(0)"
onmouseout = "messages(4)" />
</label>
<br />
<label>
Email:
<input type = "text" onmouseover = "messages(1)"
onmouseout = "messages(4)" />
</label>
<br /> <br /></p>
</form>
<form action = "">
<h3> Order Form </h3>

<table>
<tr>
<th> Product Name </th>
<th> Price </th>
<th> Quantity </th>
</tr>

<tr>
<th> French Vanilla (1 lb.) </th>
<td> $3.49 </td>
<td> <input type = "text" id = "french"
size ="2" /> </td>
</tr>
<tr>
<th> Hazlenut Cream (1 lb.) </th>
<td> $3.95 </td>
<td> <input type = "text" id = "hazlenut"
size = "2" /> </td>
</tr>
<tr>
<th> Columbian (1 lb.) </th>
<td> $4.59 </td>
<td> <input type = "text" id = "columbian"
size = "2" /></td>
</tr>
</table>


<p>
<input type = "button" value = "Total Cost"
onclick = "computeCost();" />
<input type = "text" size = "5" id = "cost"
onfocus = "this.blur();" />
</p>


<p>
<input type = "submit" value = "Submit Order" />
<input type = "reset" value = "Clear Order Form" />
</p>
</form>
</body>
</html>

JS:

 var helpers = ["Your name must be in the form: \n \
first name, middle initial., last name",
"Your email address must have the form: \
user@domain",]

function messages(adviceNumber) {
document.getElementById("adviceBox").value =
helpers[adviceNumber];
}
function computeCost() {
var french = document.getElementById("french").value;
var hazlenut = document.getElementById("hazlenut").value;
var columbian = document.getElementById("columbian").value;

document.getElementById("cost").value =
totalCost = french * 3.49 + hazlenut * 3.95 +
columbian * 4.59;
}

最佳答案

我认为这与 french、hazlenut 和 columbian 在代码中被视为字符串有关。在执行totalCost 计算之前,尝试对每个对象使用parseInt。

如果您使用的是 html 5 并且仅使用较新的浏览器,您可能会使用 input type=number 而不是 input type=text。

关于javascript - 输入数据摘要,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22920274/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com