jqury插件编写

sae中短信验证码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
; (function($) {
    $(document).ready(function() {
        if (parent && parent.location.href != location.href) parent.location.href = location.href;
        var timelineBox = $(‘.timeline-box‘) timelineBox.find(‘.progress .bar‘).each(function(k, v) {
            $(v).css(‘width‘, ‘25%‘)
        }) var retryBtn = $(‘#get-vcode‘);
        var codeBox = $(‘#verify‘);
        retryBtn.addClass(‘disabled‘).fadeIn().on(‘click‘,
        function(e) {
            e.preventDefault();
        });
        var pageTimer = function(limit, interval) {
            retryBtn.attr(‘data-ready‘, ‘loading‘).addClass(‘disabled‘).off(‘click‘).on(‘click‘,
            function(e) {
                e.preventDefault();
            });
            setTimeout(function() {
                if (limit > interval) {
                    limit -= interval;
                    retryBtn.text(‘重新获取验证码(‘ + parseInt(limit / 1000) + ‘s)‘);
                    setTimeout(arguments.callee, interval);
                } else {
                    retryBtn.attr(‘data-ready‘, ‘ready‘).text(‘重新获取验证码‘).removeClass(‘disabled‘).off(‘click‘).on(‘click‘, retryBtnFunc);
                }
            },
            interval);
        }
        pageTimer(60000, 1000);
        var retryBtnFunc = function(e) {
            e.preventDefault();
            if (retryBtn.attr(‘data-ready‘) == ‘ready‘) {
                $.ajax({
                    url: ‘/?m=user&a=send_mobile_code‘,
                    type: ‘POST‘,
                    dataType: ‘JSON‘,
                    success: function(resp, state, xhr) {
                        var success = xhr.getResponseHeader(‘reg_ok‘);
                        if (success) {
                            location.href = ‘/?m=user&a=finish_register‘;
                        } else if (xhr.getResponseHeader(‘sae_ok‘) || resp.event > 299) {
                            retryBtn.popover(‘destroy‘);
                            retryBtn.popover({
                                title: ‘系统提示‘,
                                content: resp.message
                            }).popover(‘show‘);
                            codeBox[0].select();
                            pageTimer(60000, 1000);
                        }
                    }
                }) pageTimer(60000, 1000);
            }
        }
        $(‘#verify-mobile‘).on(‘click‘,
        function(e) {
            e.preventDefault();
            var ret = $SAETOOLS.trim(codeBox.val());
            if (ret.length) {
                $.ajax({
                    url: ‘/?m=user&a=check_mobile_code‘,
                    data: ‘vcode=‘ + ret,
                    type: ‘POST‘,
                    dataType: ‘JSON‘,
                    success: function(data, state, xhr) {
                        var success = xhr.getResponseHeader(‘reg_ok‘);
                        if (success) {
                            location.href = ‘/?m=user&a=finish_register‘;
                        } else if (xhr.getResponseHeader(‘sae_ok‘) || data.event > 299) {
                            if (422 == data.event) {
                                retryBtn.popover(‘destroy‘);
                                $(‘#verify‘).popover(‘destroy‘).popover({
                                    title: ‘系统提示‘,
                                    content: data.message
                                }).popover(‘show‘);
                                $(‘#get-vcode‘).remove();
                            } else if (data.event <= 299 && data.event >= 200) {
                                location.href = ‘/?m=user&a=finish_register‘;
                            } else {
                                retryBtn.popover({
                                    title: ‘系统提示‘,
                                    content: data.message
                                }).popover(‘show‘);
                                codeBox[0].select();
                                pageTimer(60000, 1000);
                            }
                        }
                    }
                })
            } else {
                codeBox.popover(‘destroy‘);
                codeBox.popover({
                    title: ‘系统提示‘,
                    content: ‘请输入验证码,如果没有收到验证码,可以尝试发送短信到服务器进行手动验证。‘
                }).popover(‘show‘);
                codeBox[0].select();
            }
        });
        $(‘#step-second‘).on(‘click‘,
        function(e) {
            e.preventDefault();
            location.href = ‘/?m=user&a=security2‘;
        })
    })
})(jQuery)

jqury插件编写

上一篇:解决按钮回传的问题


下一篇:学习笔记 - 触摸事件&手势识别