$(document).ready(function () {
$.validator.setDefaults({
submitHandler: function () {
$('#search').submit(function () {
var city = $("#city").val();
var adults = $("#adults").val();
var children = $("#children").val();
var SDate = $("#hotelStartDate").val();
var EDate = $("#hotelEndDate").val();
SDate = SDate.substr(6, 4) + '-' + SDate.substr(3, 2) + '-' + SDate.substr(0, 2);
EDate = EDate.substr(6, 4) + '-' + EDate.substr(3, 2) + '-' + EDate.substr(0, 2);
jQuery(":submit", this).css("display", "none");
jQuery(":submit", this).after("<span class='button nice awesome green large radius'>Searching...</span>");
location.href = 'http://www.dhitrax.com/destination.php?checkin=' + SDate + '&checkout=' + EDate + '&city=' + city + '&adults=' + adults + '&children=' + children;
return false;
});
},
highlight: function (input) {
$(input).addClass("ui-state-highlight");
},
unhighlight: function (input) {
$(input).removeClass("ui-state-highlight");
}
});
$().ready(function () {
$.fn.themeswitcher && $('<div/>').css({
position: "absolute",
right: 10,
top: 10
}).appendTo(document.body).themeswitcher();
$("#search").validate({
rules: {
city: "required",
hotelStartDate: "required",
hotelEndDate: "required"
},
messages: {
City: "Please type your destination",
hotelStartDate: "Select check in Date",
hotelEndDate: "Select check out Date"
}
});
});
});
答案 0 :(得分:0)
您不应将事件处理程序绑定到现有submit
jQuery validate提供的1>} 内的submitHandler
事件。它需要两次点击才能提交表单,因为第一次提交时,处理程序已绑定,第二次提交处理程序时执行。
这应该就像将代码移到submitHandler
:
$.validator.setDefaults({
submitHandler: function () {
var city = $("#city").val();
var adults = $("#adults").val();
var children = $("#children").val();
var SDate = $("#hotelStartDate").val();
var EDate = $("#hotelEndDate").val();
SDate = SDate.substr(6, 4) + '-' + SDate.substr(3, 2) + '-' + SDate.substr(0, 2);
EDate = EDate.substr(6, 4) + '-' + EDate.substr(3, 2) + '-' + EDate.substr(0, 2);
jQuery(":submit", this).css("display", "none");
jQuery(":submit", this).after("<span class='button nice awesome green large radius'>Searching...</span>");
location.href = 'http://www.dhitrax.com/destination.php?checkin=' + SDate + '&checkout=' + EDate + '&city=' + city + '&adults=' + adults + '&children=' + children;
},
highlight: function (input) {
$(input).addClass("ui-state-highlight");
},
unhighlight: function (input) {
$(input).removeClass("ui-state-highlight");
}
});