function getquerystring(name) {
var reg = new regexp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]);
return null;
}
$(function() {
$.ajaxsetup({
async: false
});
})
function show(im) {
im.src = "/index/incx/code.aspx?" + new date;
}
$(function() {
$(".required").each(function() {
var $required = $(" * ");
$(this).parent().append($required);
});
//文本框失去焦点后
$('.required').blur(function() {
var $parent = $(this).parent();
$parent.find(".formtips").remove();
//验证标题
if ($(this).is('#tb_title')) {
if (this.value == "" || this.value.length < 4) {
var errormsg = '请输入主题,主题不能少于4字';
$parent.append('' + errormsg + '');
} else {
var okmsg = '输入正确';
$parent.append('' + okmsg + '');
}
}
//验证姓名
if ($(this).is('#tb_name')) {
if (this.value == "") {
var errormsg = '请输入姓名';
$parent.append('' + errormsg + '');
} else {
var okmsg = '输入正确';
$parent.append('' + okmsg + '');
}
}
//验证邮件
if ($(this).is('#tb_email')) {
if (this.value == "" || (this.value != "" && !/.+@.+\.[a-za-z]{2,4}$/.test(this.value))) {
var errormsg = '请输入正确的e-mail地址';
$parent.append('' + errormsg + '');
} else {
var okmsg = '输入正确';
$parent.append('' + okmsg + '');
}
}
//验证电话
if ($(this).is('#tb_phone')) {
if (this.value == "" || (this.value != "" && !/^(13[0-9]|14[0-9]|15[0-9]|18[0-9])\d{8}$/.test(this.value))) {
var errormsg = '请输入正确的联系电话';
$parent.append('' + errormsg + '');
} else {
var okmsg = '输入正确';
$parent.append('' + okmsg + '');
}
}
}).keyup(function() {
$(this).triggerhandler("blur");
}).focus(function() {
$(this).triggerhandler("blur");
});
//end blur
//提交,最终验证。
$('#msg_btn').click(function() {
$(".required").trigger('blur');
var numerror = $('.onerror').length;
if (numerror) {
return false;
}
var ymz = $("#ymz").val();
var title = $("#tb_title").val();
var name = $("#tb_name").val();
var sex = $("input[name='rbl_sex']:checked").val();
var phone = $("#tb_phone").val();
var email = $("#tb_email").val();
var objt = $("input[name='rbl_objt']:checked").val();
var content = $("#tb_content").val();
var cclass = getquerystring("class");
$.get("/inhx/guestbook.ashx", {
ymz: ymz,
title: encodeuricomponent(title),
name: encodeuricomponent(name),
sex: encodeuricomponent(sex),
phone: encodeuricomponent(phone),
email: encodeuricomponent(email),
objt: encodeuricomponent(objt),
content: encodeuricomponent(content),
cclass: cclass
},
function(data) {
if (data == "1") {
alert("留言已提交");
location = location;
}
else {
alert("验证码错误!");
}
});
});
//重置
$('#reset').click(function() {
$(".formtips").remove();
});
})