ar arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)"); if (arr = document.cookie.match(reg)) return unescape(arr[2]); else return null; } //获取来路 if(document.referrer.length > 0){ var ref = document.referrer; }else{ var ref = ''; } //判断cookie c_start = document.cookie.indexOf("incoming="); if(c_start == -1){ //设置cookie setCookie('incoming',ref); } //判断设备 function IsPC() { var userAgentInfo = navigator.userAgent; var Agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"]; var flag = true; for (var v = 0; v < Agents.length; v++) { if (userAgentInfo.indexOf(Agents[v]) > 0) { flag = false; break; } } return flag; } $('.js-in-submit').click(function() { //判断设备 var device = ''; if(IsPC()){ device = 'PC'; }else{ device = 'mobile'; } //点击 start function gtag_report_conversion(url){window.location = url;} //点击 end var $form = $(this).closest('.c-in-form'); var aa = true; // console.log($(this)) // if ($(".form-input-name").val() != ""){ // $(".form-input-name").next().html(""); // }else{ // $(".form-input-name").next().html("姓名不能为空"); // aa = false; // } // console.log($(".form-input-name").val()) // var patrn = /^(0[0-9]{2,3}\-)?([2-9][0-9]{6,7})+(\-[0-9]{1,4})?$|(^(13[0-9]|15[0|3|6|7|8|9]|18[8|9])\d{8}$)/; // if ($(".form-input-phone").val() != ""){ // $(".form-input-phone").next().html(""); // }else{ // $(".form-input-phone").next().html("联系电话不能为空"); // aa = false; // } // console.log($(".form-input-phone").val()) var patrn = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/; var email = $(this).parent().prevAll().find('.form-input-email'); if(email.val() != ""){ if (!patrn.exec(email.val())){ email.next().html("Incorrect mailbox format"); aa = false; }else{ email.next().html(""); } }else{ email.next().html("A valid email address is required."); aa = false; } if($(this).parent().prevAll().find('.form-input-message').val() != ""){ $(this).parent().prevAll().find('.form-input-message').next().html(""); }else{ $(this).parent().prevAll().find('.form-input-message').next().html("The message cannot be empty"); aa = false; } if(aa){ if($(this).attr("is_ck")=='true'){ return false; } var myDate = new Date(); var mytime=myDate.toLocaleTimeString(); //获取当前时间 var timedate = myDate.toLocaleString( ); //获取日期与时间 $(this).prop('disabled',true).attr("is_ck",'true').addClass(".disabled"); // console.log($(this)) $.ajax({ type : 'POST', dataType : 'json', url : "/wp-admin/admin-ajax.php", data : { 'action' : 'save_inquiry', 'time' : timedate, 'name' : $form.find('input[name=in_name]').val(), 'email' : $form.find('input[name=in_email]').val(), 'company': $form.find('input[name=in_company]').val(), 'phone' : $form.find('input[name=in_phone]').val(), 'url' : 'https://www.jxlcommunication.com/product/ftth-drop-cable-gjyxch/', 'message': $form.find('textarea[name=in_message]').val(), 'channel': getCookie('incoming'), 'device' : device, }, success : function(data) { console.log(data) if(data.success == true){ // $form.find('.inquiry-form').html(data.message); // window.location.href = "/message/"; setCookie('inquiry',1); gtag_report_conversion("/message/"); } else { $form.find('.c-err-msg').html(data.message); setTimeout(function(){ $('.js-in-submit').prop('disabled',false).attr("is_ck",'false').removeClass(".disabled") },2000) } }, error :function(){ $form.find('.c-err-msg').html('Busy service'); setTimeout(function(){ $('.js-in-submit').prop('disabled',false).attr("is_ck",'false').removeClass(".disabled") },2000) } }); }else{ return false; } }); });