我正在做一个需要开发交互式菜单的学校项目。由于我已经学习了几个月,所以我对 JavaScript 和 html 的许多方面的知识有限。我正在制作一个统一的菜单,理论上允许用户购买统一的物品(我实际上并没有添加支付选项)。
我需要帮助才能创建一个函数或类似的东西,它会显示您所做的选择并延续您所做的选择,这将产生一条确认消息。
在上面的屏幕截图中,假设用户想要 2 件小西装外套。因此,用户将单击小并单击输入数量并输入 2。然后用户将单击确认订单,这将显示一条确认消息,例如
You have chosen to confirm 2 small sized blazers for $400. Confirm?
问题是我不知道如何创建此消息,该消息因用户想要的大小和数量而异。
jsFiddle中的示例代码:对不起,如果这不太有意义。我已经尽力解释我的问题,所以我可能错过了重要的细节。所以如果我这样做了,请告诉我。
HTML:
<td>Blazer (All Sizes) - $200</td>
<td><button onclick="small()">Small</button>
<p><button onclick="medium()">Medium</button> </p>
<button onclick="large()">Large</button> </td>
<td><button onclick="quantitynumber()">Enter Quantity</button> </td>
<td><button onclick="confirmorder()">Confirm Order</button>
JS:
var blz = 0
function small()
{
blz = confirm ('You have selected size: Small. Confirm?')
}
function medium()
{
blz = confirm ('You have selected size: Medium. Confirm?')
}
function large()
{
blz = confirm ('You have selected size: Large. Confirm?')
}
function quantitynumber()
{
blz = prompt ('Enter the number of Blazer(s) to order')
blz1 = blz * 200
if ( blz == 1) {
blz1 = confirm ('You have chosen to order 1 Blazer for $' + blz1 + '. Confirm?')
}
else if ( blz >=2 && blz <= 5) {
blz1 = confirm ('You have chosen to order ' + blz + ' Blazers for $' + blz1 + '. Confirm?')
}
else if (blz >5) {
alert('There is a limit of 5 Blazers per customer.')
blz = null
blz1= null
}
else if (blz = isNaN || blz == '') {
alert ('Please type in a valid number.')
}
}
function confirmorder()
{
if (blz == small && blz >= 1 && blz <= 5) {
blz1 = confirm ('You have chosen to confirm ' + blz + ' small sized Blazers for $' + blz1 + '. Confirm?')
}
}