你能解决这个问题吗?我想要的是将值“checkin”和“checkout”的值传递给特定的URL。但它不适用于我的代码。
$('#submitBooking').on('click', function() {
var checkin = new Date($('#checkinbooking').val());
inDay = checkin.getDate();
inMonth = checkin.getMonth() + 1;
inYear = checkin.getFullYear();
checkin = ([inYear, inMonth, inDay].join('-'));
var checkout = new Date($('#checkoutbooking').val());
outDay = checkout.getDate();
outMonth = checkout.getMonth() + 1;
outYear = checkout.getFullYear();
checkout = ([outYear, outMonth, outDay].join('-'));
window.location.href =
'https://hotels.cloudbeds.com/reservation/oL7RdR?checkin=' + checkin + '&checkout=' + checkout;
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form action="https://hotels.cloudbeds.com/reservation/oL7RdR#/post" method="post">
<label for="checkin" class="VP"><span class="VC">From</span></label>
<input type="date" name="checkin" id="checkinbooking">
<label for="checkout" class="VP"><span class="VC">To</span></label>
<input type="date" name="checkout" id="checkoutbooking">
<input type="submit" value="Check Availability" id="submitBooking">
</form>
我已成功使用它。我做的是将方法改为get
并使用preventDefault()
和我的href
的一些变化
$('#submitBooking').on('click',
function(event){
event.preventDefault()
var checkin = new Date($('#checkinbooking').val());
inDay = checkin.getDate();
inMonth = checkin.getMonth()+1;
inYear = checkin.getFullYear();
checkin = ([inYear, inMonth, inDay].join('-'));
var checkout = new Date($('#checkoutbooking').val());
outDay = checkout.getDate();
outMonth = checkout.getMonth()+1;
outYear = checkout.getFullYear();
checkout = ([outYear, outMonth, outDay].join('-'));
window.location.href = 'https://hotels.cloudbeds.com/reservation/oL7RdR#checkin='+checkin+'&checkout='+checkout;
});
<form action="https://hotels.cloudbeds.com/reservation/oL7RdR#" method="get">
<label for="checkin" class="VP"><span class="VC">From</span></label>
<input type="date" name="checkin" id="checkinbooking">
<label for="checkout" class="VP"><span class="VC">To</span></label>
<input type="date" name="checkout" id="checkoutbooking">
<input type="submit" value="Check Availability" id="submitBooking">
</form>