【发布时间】:2021-01-12 16:25:53
【问题描述】:
我有一个字段 HrsBirthDate,它应该以 HH:MM 格式输入(可以是 00:01、01:19、23:44、19:34、13:12)。
所以在提交表单之前,我需要检查该值是否为上述任何一种格式,否则会抛出错误消息。
现在只有我可以检查该字段是否为空。
这是我的代码:
$("body").on("click", "#WebGrid TBODY .Update", function () {
var row = $(this).closest("tr");
var employee = {};
employee.EmployeeID = row.find(".EmployeeId").find(".label").html();
employee.FirstName = row.find(".Name").find(".text").val();
employee.BirthDate = row.find(".DOB").find(".text").val();
employee.HrsBirthDate = row.find(".HrsBirthDate").find(".text").val();
if (employee.FirstName != '' && employee.BirthDate != '' && employee.HrsBirthDate != '') {
debugger;
$("td", row).each(function () {
if ($(this).find(".text").length > 0) {
var span = $(this).find(".label");
var input = $(this).find(".text");
span.html(input.val());
span.show();
input.hide();
}
});
row.find(".Edit").show();
row.find(".Cancel").hide();
$(this).hide();
$.ajax({
type: "POST",
url: "/Home/UpdateEmployee",
data: '{employee:' + JSON.stringify(employee) + '}',
contentType: "application/json; charset=utf-8",
dataType: "json"
});
}
else {
alert("Please fill the details.");
return false;
}
});
【问题讨论】:
标签: javascript ajax