$(document).ready(function () { //获取登录按的事件并激活click事件 $('#btn_msg').click(function () { message(); // get_yzm(); }); }); /** * / *
  • */ function message() { var name = $('#txt_name').val(); var mail = $('#txt_mail').val(); var phone = $('#txt_tel').val(); var wt = $('#txt_count').val(); var id = 44; //$('#h_id').val(); if (name== '') { alert('请输入姓名'); $('#txt_name').focus(); return false; } if (phone == '') { alert('请输入联系方式'); $('#txt_tel').focus(); return false; } if (!checkphone(phone)) { alert('请输入有效的手机号码'); // alert('请输入有效的手机号码 '); $('#txt_tel').focus(); return false; } if (!checkemail(mail)) { alert('请输入正确的邮箱'); $('#txt_mail').focus(); return false; } if (wt=='') { alert('请输入内容'); $('#txt_count').focus(); return false; } //if (mail == '') { // alert('请输入邮箱'); // $('#txt_email').focus(); // return false; //} //if (!checkemail(mail)) { // alert('请输入正确的电子邮箱 '); // $('#txt_email').focus(); // return false; //} $.ajax({ type: 'post', //url方式为post url: 'p_message.aspx', //这里是指向登录验证的页面 data: { "titles": name, "username": name, "mail":mail, "tel": phone, "txt": wt, // zx:"zx", // username : "name_x"+, // name_y :: $('#txt_name_n').val(), // mail : $('#txt_email').val(), // phone : $('#txt_phone').val(), // cname : $('#txt_cname').val(), //wt = $('#txt_wt').val(), "t": math.random() }, datatype: "json", //把要验证的参数传过去 //数据类型为json格式的验证 //在发送数据之前要运行的函数 // beforesend: function () { // $('#confirm').html('登录中.........'); // }, success: function (json) { //这是个重点,根据验证页面(login.aspx)输出的json格式数据判断是否登录成功 //这里我用1表示的 //sta就是那个输出到客户端的标示 if (json.sta == 1) { alert("留言已提交 请等候管理员联系"); $('#txt_name').val(""); $('#txt_mail').val(""); $('#txt_tel').val(""); $('#txt_count').val(""); } else { alert(json.info); } } }); } function checkemail(email) { var emailregexp = new regexp("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?"); if (!emailregexp.test(email) || email.indexof('.') == -1) { return false; } else { return true; } } function checkphone(phone) { if (phone && /^1[3|4|5|7|8]\d{9}$/.test(phone)) { return true; } else { return false; } } //function get_yzm() { // document.getelementbyid("img_yz_s").src = "/ashx/img_yz.ashx?" + math.random().tostring(); // }