在线提交

在线提交_第1张图片
image.png

















前台代码:
function submi() {
var name = $("#name").val();//姓名
if (name == "") {
$("#war_Out").show();
$("#war_Danger").html("温馨提示:请填写您的姓名");
$("#name").focus();
timeload();
return;
}
var telephone = $("#telephone").val();//电话
if (telephone == "") {
$("#war_Out").show();
$("#war_Danger").html("温馨提示:请填写您的手机号码");
$("#telephone").focus();
timeload();
return;
}
if (!$("#telephone").val().match(/^1[34578]\d{9}$/)) {
$("#war_Out").show();
$("#war_Danger").html("温馨提示:手机格式不正确");
$("#telephone").focus();
timeload();
return;
}
var email = $("#email").val();//邮箱
if (email == "") {
$("#war_Out").show();
$("#war_Danger").html("温馨提示:请填写邮箱");
$("#email").focus();
timeload();
return;
}
if (!$("#email").val().match(/^\w+((-\w+)|(.\w+)) @[A-Za-z0-9]+((.|-)[A-Za-z0-9]+).[A-Za-z0-9]+$/)) {
$("#war_Out").show();
$("#war_Danger").html("温馨提示:邮箱格式不正确");
$("#email").focus();
timeload();
return;
}
var company = $("#company").val();//公司名称
if (company == "") {
$("#war_Out").show();
$("#war_Danger").html("温馨提示:公司名称不能为空");
$("#company").focus();
timeload();
return;
}
var suggest = $("#suggest").val();
if ($.trim(suggest) == "") {
$("#war_Out").show();
$("#war_Danger").html("温馨提示:留言信息没有填写");
$("#suggest").focus();
timeload();
return;
}
var val = "contact_Name,contact_Telephone,contact_Email,contact_Company,contact_Content";
var html = "&contact_Name=" + name + "&contact_Telephone=" + telephone + "&contact_Email=" + email + "&contact_Company=" + company + "&contact_Content=" + suggest;
$.ajax({
type: "post",
dataType: "text",
url: "ashx/timely.ashx",
data: "our=及时沟通" + html+"&val="+val,
success: function (msg) {
if (msg == "True") {
$("#war_Out").show();
$("#war_Danger").html("稍后我们会与您取得联系,谢谢!");
clear();
timeload();
}
},
error: function (xml) {
alert("系统繁忙,请稍后");
}
});
}
//提示框消失
function timeload()
{
$('#war_Out').delay(2000).hide(0);
}
//文本框清空
function clear()
{
$("#name").val("");//姓名
$("#telephone").val("");//电话
$("#email").val("");//邮箱
$("#company").val("");//公司名称
$("#suggest").val("");//内容
}

后台代码:

主要思路是:验证手机,邮箱,内容是否为空,然后提交成功后,清空所有文本框,防止用户恶意点击。

你可能感兴趣的:(在线提交)