gpt4 book ai didi

php - jquery提交需要点击两次

转载 作者:行者123 更新时间:2023-12-01 05:57:52 25 4
gpt4 key购买 nike

$(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"
}
});
});
});

最佳答案

您不应该将事件处理程序绑定(bind)到现有 submitHandler jQuery validate 提供的 内部submit 事件。需要单击两次才能提交表单,因为第一次提交时会绑定(bind)处理程序,第二次提交时会执行处理程序。

这应该像将代码移动到 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");
}
});

关于php - jquery提交需要点击两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13657395/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com