我已经使用 jqueryui-date 选择器构建了一个表单 - 基本上,如果结束日期小于或等于开始时间,它需要显示一条消息,说明它必须大于开始时间,然后才能允许用户提交表单。看不到我哪里出错了。
提交代码如下
protected void btnSubmit_Click(object sender, EventArgs e)
{
DateTime startDate = Convert.ToDateTime(txtStartDate.Text + " " + ddlTime.SelectedValue);
DateTime endDate = Convert.ToDateTime(txtEndDate.Text + " " + ddlTime2.SelectedValue);
if (startDate >= DateTime.Now)
{
if (endDate <= startDate)
{
usrComment.Visible = true;
//usrComment.Text = "Return time needs to be greater than pickup time IF same day";
usrComment.Text = "Date =" + startDate + "Date 2 =" + endDate;
}
else
{
if (Page.IsValid)
{
string EmailServer = WebConfigurationManager.AppSettings["Email.Server"];
int ServerPort = Int32.Parse(WebConfigurationManager.AppSettings["Email.ServerPort"]);
string EmailServerUser = (WebConfigurationManager.AppSettings["Email.UserName"]);
string EmailServerPass = (WebConfigurationManager.AppSettings["Email.Password"]);
string EmailFrom = (WebConfigurationManager.AppSettings["Email.From"]);
string EmailTo = (WebConfigurationManager.AppSettings["Email.To"]);
string EmailToUser = txtEmail.Text;
string EmailSubject = "Quote Form submitted";
****.****.*****.Email m = new ****.****.Helpers.Email(EmailServer, ServerPort, EmailServerUser, EmailServerPass);
StringBuilder html = new StringBuilder();
html.AppendLine("<ul>");
html.AppendLine("<li>" + lblName.Text + ": " + txtName.Text + "</li>");
html.AppendLine("<li>" + lblEmail.Text + ": " + txtEmail.Text + "</li>");
html.AppendLine("<li>" + lblPhone.Text + ": " + txtPhone.Text + "</li>");
html.AppendLine("<li>" + lblVehicleType.Text + ": " + ddlVehicleType.SelectedValue + "</li>");
html.AppendLine("<li>" + lblPickupDate.Text + ": " + txtStartDate.Text + "</li>");
html.AppendLine("<li>" + ddlTime.SelectedValue + "</li>");
html.AppendLine("<li>" + lblReturnDate.Text + ": " + txtEndDate.Text + "</li>");
html.AppendLine("<li>" + ddlTime2.SelectedValue + "</li>");
html.AppendLine("</ul>");
m.SendHTMLEmail(EmailFrom, EmailTo, EmailSubject, html.ToString());
//Response.Redirect("/contact-us/quote-form-submitted.aspx");
}
usrComment.Text = "SUBMIT IT NOW!!!!!";
}
}
}
用于日期选择器的 jQuery
$(function () {
function getDiff() {
var from = $(".start").val();
var till = $(".fin").val();
var c = from.split("/");
beg = new Date(c[2], c[1] - 1, c[0]);
var d = till.split("/");
en = new Date(d[2], d[1] - 1, d[0]);
var rest = (en - beg) / 86400000;
var txt = rest == 0 ? "" : rest + " days"
$("#res").text(txt);
}
$(".start").datepicker({
changeMonth: false,
changeYear: false,
showAnim: "fadeIn",
gotoCurrent: true,
minDate: 0, //change this to +3 to start 3 days from now
dateFormat: "dd/mm/yy",
onSelect: function (dateText, inst) {
$(".fin").val(dateText);
$(".fin").datepicker("option", "minDate", dateText);
getDiff();
}
});
$(".fin").datepicker({
dateFormat: "dd/mm/yy",
changeMonth: true,
changeYear: true,
showAnim: "fadeIn",
onSelect: getDiff
});
//Disabling Copy, Paste, Cut
$('.start').bind('paste', function (e) {
e.preventDefault();
//alert("You cannot paste text into this textbox!");
window.alert = function () { };
});
$('.fin').bind('paste', function (e) {
e.preventDefault();
//alert("You cannot paste text into this textbox!");
window.alert = function () { };
});
});
因此,如果您的取件日期为 2013 年 9 月 17 日,取件时间为 08:00,退货日期和时间相同,则它应该通过消息提醒您,如果退货日期大于或等于开始时间,则退货接送时间需要大于 08:00 是否有意义?