我在让脚本工作时遇到问题。
它适用于日期范围1,但不适用于日期范围2.而使事情变得更加奇怪的是每次按下按钮后它都不会重新加载。
<div class="costs">
<p><input type="text" id="datepicker" id="date" name="date" value="Choose when you want to go" style="background:#fff;"></p>
<select name="roomtype" id="roomtype" value="What room type would you like?">
<option value="Classic">Classic</option>
<option value="Luxury Room">Luxury Room</option>
<option value="Suite">Suite</option>
</select>
<select name="night" id="night" value="How many nights are you going for?">
<option value="3">3</option>
<option value="5">5</option>
<option value="7">7</option>
</select>
<select name="room" id="room" value="How many people to a room?">
<option value="Single">Single</option>
<option value="Double">Double</option>
</select>
<div>
Cost:<br>
<button onclick="checkCosts()">Get Cost</button>
<p id="cost">Choose a date and press the "Get Cost" button, to find out how much it will cost for your next African Golf Safari trip</p>
</div>
<script>
function checkCosts() {
var date = document.getElementsByName("date")[0].value;
var roomtype = document.getElementsByName("roomtype")[0].value;
var night = document.getElementsByName("night")[0].value;
var room = document.getElementsByName("room")[0].value;
var month = date.substring(0, 2);
var year = date.substring(8, 10);
var day = date.substring(4,6);
var time = month.concat(year);
var fulldate = parseInt(day.concat(time));
var inttime = parseInt(time);
//=================================
//Date Range 1
//Check earliest date
if(inttime >= 415){
//Check latest date
if(inttime <= 915){
//Classic Roomtype
if(roomtype == "Classic"){
//Nights Double
if(room = "Double"){
if(night == "3"){document.getElementById("cost").innerHTML = "1,480";}
if(night == "5"){document.getElementById("cost").innerHTML = "1,450";}
if(night == "7"){document.getElementById("cost").innerHTML = "1,415";}
}
//Nights Single
if(room = "Single"){
if(night == "3"){document.getElementById("cost").innerHTML = "2,575";}
if(night == "5"){document.getElementById("cost").innerHTML = "2,510";}
if(night == "7"){document.getElementById("cost").innerHTML = "2,440";}
}
}
//End
//Luxury Roomtype
if(roomtype == "Luxury"){
//Nights
if(room = "Double"){
if(night == "3"){document.getElementById("cost").innerHTML = "1,620";}
if(night == "5"){document.getElementById("cost").innerHTML = "1,580";}
if(night == "7"){document.getElementById("cost").innerHTML = "1,535";}
}
//Nights Single
if(room = "Single"){
if(night == "3"){document.getElementById("cost").innerHTML = "2,830";}
if(night == "5"){document.getElementById("cost").innerHTML = "2,760";}
if(night == "7"){document.getElementById("cost").innerHTML = "2,685";}
}
}
//End
//Suite Roomtype
if(roomtype == "Suite"){
//Nights
if(room = "Double"){
if(night == "3"){document.getElementById("cost").innerHTML = "1,860";}
if(night == "5"){document.getElementById("cost").innerHTML = "1,815";}
if(night == "7"){document.getElementById("cost").innerHTML = "1,770";}
}
//Nights Single
if(room = "Single"){
if(night == "3"){document.getElementById("cost").innerHTML = "3,300";}
if(night == "5"){document.getElementById("cost").innerHTML = "3,235";}
if(night == "7"){document.getElementById("cost").innerHTML = "3,145";}
}
}
//End
}
}
}
//=================================
//Date Range 2
//Check earliest date
if(inttime >= 1015){
//Check latest date
if(inttime <= 316){
//Classic Roomtype
if(roomtype == "Classic"){
//Nights Double
if(room = "Double"){
if(night == "3"){document.getElementById("cost").innerHTML = "1,480";}
if(night == "5"){document.getElementById("cost").innerHTML = "1,450";}
if(night == "7"){document.getElementById("cost").innerHTML = "1,415";}
}
//Nights Single
if(room = "Single"){
if(night == "3"){document.getElementById("cost").innerHTML = "2,575";}
if(night == "5"){document.getElementById("cost").innerHTML = "2,510";}
if(night == "7"){document.getElementById("cost").innerHTML = "2,440";}
}
}
//End
//Luxury Roomtype
if(roomtype == "Luxury"){
//Nights
if(room = "Double"){
if(night == "3"){document.getElementById("cost").innerHTML = "1,620";}
if(night == "5"){document.getElementById("cost").innerHTML = "1,580";}
if(night == "7"){document.getElementById("cost").innerHTML = "1,535";}
}
//Nights Single
if(room = "Single"){
if(night == "3"){document.getElementById("cost").innerHTML = "2,830";}
if(night == "5"){document.getElementById("cost").innerHTML = "2,760";}
if(night == "7"){document.getElementById("cost").innerHTML = "2,685";}
}
}
//End
//Suite Roomtype
if(roomtype == "Suite"){
//Nights
if(room = "Double"){
if(night == "3"){document.getElementById("cost").innerHTML = "1,860";}
if(night == "5"){document.getElementById("cost").innerHTML = "1,815";}
if(night == "7"){document.getElementById("cost").innerHTML = "1,770";}
}
//Nights Single
if(room = "Single"){
if(night == "3"){document.getElementById("cost").innerHTML = "3,300";}
if(night == "5"){document.getElementById("cost").innerHTML = "3,235";}
if(night == "7"){document.getElementById("cost").innerHTML = "3,145";}
}
}
//End
}
}
</script>
Find on: https://jsfiddle.net/zo7xr42j/
(//=========
就是我可以分开的东西)
我假设按钮应该重新加载价格的原因是它在每个其他页面(使用类似代码)上的工作方式相同 可以找到
http://www.africangolfsafari.com/mountains-wine/
答案 0 :(得分:0)
你的
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<table class="mytable">
<thead>
<tr>
<th>Group</th>
<th>Amount</th>
</tr>
<thead>
<tbody>
<tr>
<td>x</td>
<td>3</td>
</tr>
<tr>
<td>x</td>
<td>1</td>
</tr>
<tr>
<td>test</td>
<td>2</td>
</tr>
<tr>
<td>test</td>
<td>5</td>
</tr>
</tbody>
</table>
不在函数 //Date Range 2
//Check earliest date
if (inttime >= 1015) {
中,所以当浏览器读取代码时,var还没有存在。