//字符串去空格 function trim(str) { return str.replace(/^(\s|\u00A0)+/, '').replace(/(\s|\u00A0)+$/, ''); } //用户名校验 function checkUserName() { var str = trim($("#iname").val()); if (str != '匿名用户') { if (str == "" || str == undefined || str == null) { $("#iname").focus(); $("#iname").css("border", "1px solid #c31a00"); $('#ruserName').css('display', 'inline-block').text('用户民不能为空!'); return false; } else { var len = 0; for (var i = 0; i < str.length; i++) { var a = str.charAt(i); if (a.match(/[^\x00-\xff]/ig) != null) { len += 2; } else { len += 1 } } if (len > 20) { $("#iname").focus(); $("#iname").css("border", "1px solid #c31a00"); $('#ruserName').css('display', 'inline-block').text('用户名长度不能超过20个字符'); return false; } else { $('#ruserName').css('display', 'none'); $("#iname").css("border", "1px solid #ccc"); return true; } } } } //联系方式校验 function checkContact() { var str = trim($("#itel").val()); if (str == "" || str == undefined || str == null) { $("#itel").focus(); $("#itel").css("border", "1px solid #c31a00"); $('#rtel').css('display', 'inline-block').text('请填写有效电话号码或邮箱!'); return false; } else { var rTel = /^1\d{10}$/; var rEmail = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/; if (rTel.test(str) || rEmail.test(str)) { $('#rtel').css('display', 'none'); $("#itel").css("border", "1px solid #ccc"); return true; } else { $("#itel").focus(); $("#itel").css("border", "1px solid #c31a00"); $('#rtel').css('display', 'inline-block').text('请填写有效电话号码或邮箱'); return false; } } } //获取验证码 function getVerifyCode() { $.ajax({ url: getPath() + "/api/v1/Common/GetVerificationCode", type: "post", data: { Type: 1, Modular: "Feedback", t: getTime(), }, success: function (res) { $("#verifyCode").val(res.Data.Code); $(".yanz-code").css('border', 'none'); $(".body-yanzlabel").css('display', 'inline-block'); drawPic(res.Data.Code); $("#time").val(res.Data.ExpiryTime); $('#countdown').css('display', 'inline-block'); countDownTime(); //倒计时 } }) } //倒计时 function countDownTime() { var time = $("#time").val(); var countdown = formatTime(time); if (countdown) { $(".countdown").text(countdown); setTimeout("countDownTime()", 1000); } else { if (time != '') { //请求验证码 getVerifyCode(); } } } //验证码校验 function checkVerifyCOde() { if (trim($("#iCode").val().toUpperCase()) != '') { if (trim($("#iCode").val().toUpperCase()) != $("#verifyCode").val()) { $("#iCode").css("border", "1px solid #c31a00"); $("#rCode").css('display', 'inline-block'); $("#iCode").focus(); return false; } else { $("#iCode").css("border", "1px solid #ccc"); $("#rCode").css('display', 'none'); return true; } } } function postAdvice() { if (checkContact && checkUserName && checkVerifyCOde) { var NickName = trim($("#iname").val()), Contact = trim($("#itel").val()), VerificationCode = trim($("#iCode").val()), Content = trim($("#icontent").val()); if (Content == "") { return false; } $.ajax({ url: getPath() + "/api/v1/Common/SubmitFeedback", type: "post", data: { VerificationCode: VerificationCode, NickName: NickName, Contact: Contact, Content: Content, t: getTime(), }, success: function (res) { if (res.Status == 200) { alert("提交成功"); $("#iname").val('匿名用户'); $("#itel").val(''); $("#icontent").val(''); $("#iCode").val(''); $("#rCode").val(''); $("#time").val(''); $(".yanz-code").css('border', '1px solid #ccc'); $(".body-yanzlabel").css('display', 'none'); $('#countdown').css('display', 'none'); $(".post-label").css('display', 'none'); } else { alert(res.Message); } } }) } }