Javascript函数双倍数量 [英] Javascript function double amounts

查看:89
本文介绍了Javascript函数双倍数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将酒店金额与每天的金额联系起来。例如,如果您选择入住经济型酒店两天,则会使酒店的数量翻倍,而不是仅仅在酒店住宿的金额翻倍。我已经创建了一个变量,并将其添加到我的if语句中以检索该值。它正在正确地检索一天的金额,但是一旦我添加了该变量,它开始加倍翻转。









当用户提交表格时,费用估算他们的行程应出现在一个包含所有选项的警告框中:

I'm trying to connect the hotel amount with the amount per day. For instance, if you select two days staying at the Economy hotel, it doubles the amount rather than doubling the amount for they the stay at the hotel alone. I've created a variable for days and added it to my if statements to retrieve the value. It was retrieving the amount for a single day correctly, but once I added that variable it began doubling everthing else.




When the user submits their form, a cost estimate for their trip should appear in an alert box with all the options:

Quote:

到达城市:使用单选按钮。选择应该是奥马哈(200美元),纳什维尔(250美元),底特律(150美元)

作为选择框的天数,选项从2到6

选择框为'额外行李(每个30美元)'。选项应为'No Extra Bags','1 Extra Bag','2 Extra Bags','3 Extra Bags'

有以下复选框:带宠物($ 60)
用于选择酒店类型的单选按钮:经济型酒店(140美元),标准酒店(220美元),高档酒店(300美元)

Arrival City: Use a radio button. Choices should be Omaha ($200), Nashville ($250), Detroit ($150)
Number of days as a select box with options from 2 through 6
Select box for ‘Extra Baggage ($30 each)’. Options should be ‘No Extra Bags’, ‘1 Extra Bag’, ‘2 Extra Bags’, ‘3 Extra Bags’
Have a checkbox for the following: Bringing a pet ($60)
A radio button to select the type of hotel: Economy Hotel ($140), Standard Hotel ($220), Upscale Hotel ($300)





这就是我到目前为止所拥有的。





This what I have so far.

<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="utf-8">
	<script type="text/Javascript">
		function arrivalCity ()
		{
		var cost = 0;
		var days;
		var radHotel;

		days = document.reservation.selDay.value;


			if (document.reservation.radCity[0].checked)
				{
					cost = 200;
				}
			if (document.reservation.radCity[1].checked )
				{
					cost = 250;
				}
			if (document.reservation.radCity[2].checked)
				{
					cost = 150;
				}
			if (document.reservation.chkYes.checked)
				{
					cost = cost + 60;
				}
			if (document.reservation.radHotel[0].checked)
				{
					cost = cost + 140;
				}
			if (document.reservation.radHotel[1].checked)
				{
					cost = cost + 220;
				}
			if (document.reservation.radHotel[2].checked)
				{
					cost = cost + 300;
				}
			if ( days == "two")
				{
					cost = cost * 2  ;
				}

			alert (cost) ;
		}
</script>
</head>
<body>
<div id="header">
	<form name="reservation">
		<p>Where are you traveling to? <br/>
			Omaha <input type ="radio" name="radCity"> <br>
			Nashville <input type="radio" name="radCity"><br>
			Detroit <input type="radio" name="radCity"> </p>

		<p>How many days are you staying?<br>
			<select name="selDay">
				<option value="two"> 2 </option>
				<option value="three"> 3 </option>
				<option value"four"> 4 </option>
				<option value="five"> 5 </option>
				<option value="six"> 6 </option>
			</select></p>

		<p>Extra Baggage ($30 each): <br>
			<select name="selBag">
				<option value="noBag"> No Extra Bags</option>
				<option value="oneBag"> 1 Extra Bag</option>
				<option value="twoBag">2 Extra Bags</option>
				<option value="threeBag"> 3 Extra Bags</option>
			</select> </p>

		<p>Bringing a pet ($60):<br>
			Yes <input type="checkbox" name="chkYes"><br>
			No <input type="checkbox" name="chkNo"> <br> </p>

		<p>Select the name of the hotel:<br>
		Economy Hotel <input type="radio" name="radHotel" value="$140"><br>
		Standard Hotel <input type="radio" name="radHotel" value="$220"><br>
		Upscale Hotel <input type="radio" name="radHotel" value="$300"><br>
		</select></p>



	<p><input type="button" value="Book My Ticket" onclick="arrivalCity ()"> </p>


</body>
</html><pre lang="Javascript">

推荐答案

200),纳什维尔(
200), Nashville (


250),底特律(

150)

作为选择框的天数,选项从2到6

选择额外行李框
150)
Number of days as a select box with options from 2 through 6
Select box for ‘Extra Baggage (


这篇关于Javascript函数双倍数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆