码迷,mamicode.com
首页 > 其他好文 > 详细

一个专题多个表单,a标签点击弹窗

时间:2020-05-10 09:13:46      阅读:73      评论:0      收藏:0      [点我收藏+]

标签:oca   ima   多个   rand   query   cookie   inpu   attr   arch   

// 全局JS
// wow = new WOW(
//     {
//         animateClass: ‘animated‘,
//         offset: 100,
//         callback: function (box) {
//             console.log("WOW: animating <" + box.tagName.toLowerCase() + ">")
//         }
//     }
// );
// wow.init();


// 预约
function Validate(frm) {}

function ChangeCode() {
    document.getElementById("imgcode").src = "http://www.huatu.com/other/yuyue/include/imgcode.php?id=" + Math.random();
}

var mobile;

function sendnum(obj) {
    var objForm = $(obj).parents(‘form‘).get(0);
    var shouji = $(objForm).find(‘input[name="mobile"]‘).val();
    var objFormName = $(objForm).attr(‘name‘);
    console.log($(obj))
    console.log(shouji)
    console.log(objFormName)

    // var shouji = $(‘#shoujihao‘).val();


    if (!shouji) {
        alert(‘请输入手机号‘);
        return false;
    }


    if (!(/^(1[0-9]{10})$/.test(shouji))) {
        alert(‘请输入有效的手机号码!‘);
        return false;
    }
      $(objForm).find(‘.fs‘).attr(‘disabled‘, true);
    var SysSecond;
    var InterValObj;
    SysSecond = 60;
    InterValObj = window.setInterval(SetRemainTime, 1000);

    function SetRemainTime() {
        if (SysSecond > 0) {
            SysSecond = SysSecond - 1;
            var second = Math.floor(SysSecond % 60);
            var minite = Math.floor((SysSecond / 60) % 60);
            var hour = Math.floor((SysSecond / 3600) % 24);
            var day = Math.floor((SysSecond / 3600) / 24);
            $(objForm).find(‘.fs‘).val(second + ‘秒‘);
        } else {
            window.clearInterval(InterValObj);
            $(objForm).find(‘.fs‘).val(‘发送短信‘);
            $(objForm).find(‘.fs‘).attr(‘disabled‘, false);
        }
    }
    $.getJSON(‘http://www.huatu.com/other/yuyue/duanxin/xiebodx.php?callback=?‘, {
        ‘tel‘: shouji,
        ‘appinfoid‘: $(objForm).find(‘input[name=appinfoid]‘).val()
    }, function (data) {
    if (data.click == ‘0‘) {
            if (data.address == 0 || data.address == ‘‘) {
                var tempnum = parseInt(Math.random()*10000);
                alert(‘您已参加活动!验证码‘+tempnum);
                $(objForm).find(‘.PhoneCode‘).val(tempnum);
                $(‘.window_wrap‘).hide()
                
                var exp = new Date();
                exp.setTime(exp.getTime() + 60 * 5000);
                document.cookie = ‘cooknum=‘ + tempnum + ‘;expires=‘ + exp.toGMTString();
                document.cookie = ‘cookmobile=‘ + shouji + ‘;expires=‘ + exp.toGMTString();
                return false;
            }
            // else {
            //     alert(‘您的手机号已参加活动!点击跳转至活动页...‘);
            //     window.location.href = data.address;
            // }
        } else {
            var num = data.click;
            var exp = new Date();
            exp.setTime(exp.getTime() + 60 * 5000);
           document.cookie = ‘cooknum=‘ + num + ‘;expires=‘ + exp.toGMTString();
            mobile = data.mobile;
            document.cookie = ‘cookmobile=‘ + mobile + ‘;expires=‘ + exp.toGMTString();
            $(‘#yzm‘).val(num);
            alert(‘发送成功‘);

        }
    });



}
function jiancha(obj) {
  // 来源
    var url = window.location.search.substr(1);
    $(‘input[name=Ext5]‘).val(url);
    // console.log($(‘input[name=Ext5]‘).val());

    var objForm = $(obj).parents(‘form‘).get(0);
    var objFormName = $(objForm).attr(‘name‘);

    var goToUrl = $(obj).attr("data-data");
    // console.log(goToUrl)

    // console.log($(obj))
    // console.log(objForm)
    // console.log(objFormName)
    // console.log($(objForm).attr(‘action‘))

    var url = getQueryString(‘bd_vid‘);
    var classNow = $(obj).attr(‘statistics‘);
    if (url != null) {
        $.getJSON(‘http://30fen.huatu.com/api/bd_vid.php‘, {
            ‘act‘: ‘chk‘,
            ‘statistics‘: classNow,
        }, function(data) {
            // console.log(data);
        })
    }
  var getNum = $(objForm).find(‘input[name="PhoneCode"]‘).val();


    var cook = getCookie(‘cooknum‘);
    var cookmobile = getCookie(‘cookmobile‘);

    var shouji = $(objForm).find(‘input[name="mobile"]‘).val();
//  console.log(shouji)
    if (cookmobile != shouji) {
        alert(‘手机号和验证码不一致‘);
        return false;
    } else {
        if (getNum == cook) {

            if(!Validator.Validate(objForm,2)){
                return false;
            }
            var formdata = $(objForm).serializeArray()
            // console.log(formdata)
            $.ajax({
                type: ‘post‘,
                url : $(objForm).attr(‘action‘),
                data:formdata,
                dataType:‘text‘,
                success : function (res) {
                    // console.log($(objForm).attr(‘action‘))
                    // console.log(res)
                    // console.log(goToUrl)
                    if(/存在相同记录/.test(res)){
                        alert(‘预约成功‘);
                        // window.location.href = goToUrl;
                        $(‘.window_wrap‘).hide()
                        return false;
                    }else if(/预约成功/.test(res)){
                        alert(‘恭喜您预约成功‘);
                        // window.location.href = goToUrl;
                        $(‘.window_wrap‘).hide()
                    }
                }
            })
        } else {
            alert(‘短信验证码错误‘);
            return false;
        }
    }

}

function getCookie(name) {
    var arr, reg = new RegExp(‘(^| )‘ + name + ‘=([^;]*)(;|$)‘);
    if (arr = document.cookie.match(reg))
        return unescape(arr[2]);
    else
        return null;
}

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;
}
// 弹窗限制
$(‘.box a‘).click(function () {
    // console.log(‘点击到了‘);
    var cookmobile = getCookie(‘cookmobile‘);
    if (!cookmobile) {
        // console.log(‘还未注册‘);
        $(‘.window_wrap‘).show();
        return false;
    }
});
$(‘#wrap_close‘).click(function () {
    // console.log("点击到了");
    $(‘.window_wrap‘).hide()
})

一个专题多个表单,a标签点击弹窗

标签:oca   ima   多个   rand   query   cookie   inpu   attr   arch   

原文地址:https://www.cnblogs.com/tangsujuan/p/12861481.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!