msg.js
1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
$(document).ready(function () {
$(".send").click(function () {
if ($("#msgform input[name=name]").val().replace(/\s/g, "") == "您的称呼") {
//alert("请填写您的称呼!");
$("#msgform input[name=name]").next().next().html("请填写您的称呼!");
return false;
} else {
$("#msgform input[name=name]").next().next().html("");
}
if ($("#msgform input[name=email]").val().replace(/\s/g, "") == "您的邮箱") {
//alert("请填写您的邮箱!");
$("#msgform input[name=email]").next().next().html("请填写您的邮箱!");
return false;
} else {
var reg = /\w+((-w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+/;
if (!reg.test($("#msgform input[name=email]").val())) {
$("#msgform input[name=email]").next().next().html("请输入正确的邮箱");
return false;
} else {
$("#msgform input[name=email]").next().next().html("");
}
}
if ($("#msgform textarea[name=content]").val().replace(/\s/g, "") == "") {
//alert("请填写留言内容!");
$("#msgform textarea[name=content]").next().html("请填写留言内容!");
return false;
}
$.ajax({
type: "post",
dataType: "html",
data: $("#msgform").serialize(),
url: "/Tools/msg.ashx",
success: function (result) {
if (result == "success") {
alert("留言提交成功!");
window.location.reload();
}
else {
if (result == 1) {
alert("必填项不能为空!");
} else {
alert("系统繁忙,请稍后再试!");
}
}
}
});
});
});