function submitKH(mobileInputId,nameInputId) {
var mobileInputSelector ='#'+ mobileInputId;
var passwordInputIdInputSelector = '#'+ passwordInputId;
var nameInputIdInputSelector = '#'+ nameInputId;
var mobile = jQuery(mobileInputSelector).val();
var name = jQuery(nameInputIdInputSelector).val();
var password = jQuery(passwordInputIdInputSelector).val();
var localUrl = document.location;
var source="wap";
var type="开户";
if (name.length == 0||name=="请输入您的姓名") {
alert("您的姓名不能为空!");
jQuery(nameInputIdInputSelector).focus();
return false;
}
if (password.length == 0||password=="输入您的密码") {
alert("您的密码不能为空!");
jQuery(passwordInputSelector).focus();
return false;
}
if (mobile.length == 0||mobile=="请输入您的手机号码") {
alert("您的手机号码不能为空!");
jQuery(mobileInputSelector).focus();
return false;
} if (mobile.length > 0) {
var ab = /^(13[0-9]|15[0-9]|18[0-9])\d{8}$/;
if (ab.test(mobile) == false) {
alert("您的手机号码不正确!");
jQuery(mobileInputSelector).focus();
return false;
}
}
jQuery.ajax({
type: "get",
url: "/KZH/AddNewKH",
data: "mobile=" + mobile +"&password="+password+ "&name="+name+"&source="+source+"&type=" + type + "&t=" + new Date().toString(),
dataType: "jsonp",
success: function (result) {
if (result.success == true) {
jQuery(mobileInputSelector).val("");
jQuery(passwordInputSelector).val("");
jQuery(nameInputIdInputSelector).val("");
alert("恭喜您,提交成功!");
$("#ycbox").css('display','block');
setCookie('name',name);
setCookie('phone',mobile);
}
else if(result.success == false)
{
alert("您已预约成功,无需重复提交,客服会尽快与您取得联系!");
$("#ycbox").css('display','block');
jQuery(mobileInputSelector).val("");
jQuery(passwordInputSelector).val("");
jQuery(nameInputIdInputSelector).val("");
}
}
});
}
调用:
submitKH('mobile','password','name'); return false;