邀请有礼活动页面总结(2)jsBridge和防止重复点击问题

jsBridge

 <script type="text/javascript" src="{stl.siteurl}/js/jsbridge.js"></script> 

 

setupWebViewJavascriptBridge(function (bridge) {
            bridge.callHandler('sharef', function (data) {
                var json = JSON.parse(data)
                sessionStorage.setItem('token', json.token)
                 if (json.token != '') {成功}
else{不成功} }) })

 

‘sharef’这个要和手机端的商量好,他们会给token

jsbridge.js

function setupWebViewJavascriptBridge(callback) {
//Android使用
            if (window.WebViewJavascriptBridge) {
                callback(WebViewJavascriptBridge)
            } else {
                document.addEventListener(
                    'WebViewJavascriptBridgeReady'
                    , function() {
                        callback(WebViewJavascriptBridge)
                    },
                    false
                );
            }


//iOS使用
            if (window.WebViewJavascriptBridge) { return callback(WebViewJavascriptBridge); }
            if (window.WVJBCallbacks) { return window.WVJBCallbacks.push(callback); }
            window.WVJBCallbacks = [callback];
            var WVJBIframe = document.createElement('iframe');
            WVJBIframe.style.display = 'none';
            WVJBIframe.src = 'wvjbscheme://__BRIDGE_LOADED__';
            document.documentElement.appendChild(WVJBIframe);
            setTimeout(function() { document.documentElement.removeChild(WVJBIframe) }, 0)
        }

防止重复点击问题

 //点击分享给好友
 $('#red').click(function () {
     if(flag){
         flag = false;
         if (data0 == '') {
             //如果在userInfo获取的token是空的话调用登录
             unlogged();
            } else {//如果不是"",证明登录过
            logged();
        }
        setTimeout('flag = true',5000);
    }
});

 

在获取验证码的防止重复点击问题

var wait = 60
var flag = true;

get_code_time = function (time) {
        if (wait == 0) {
            time.removeAttribute('disabled');
            $('.getCode').text('获取验证码');
            wait = 60;
            flag = true;
        } else {
            time.setAttribute("disabled", true);
            $('.getCode').text('倒计时' + wait + "秒");
            wait--;
            setTimeout(function () {
                get_code_time(time);
            }, 1000)
        }
    }
        //获取验证码     
        $('.getCode').click(function () {
         if(flag){ 
            var time = this
            if ($('#phone').val() == '') {
                window.wxc.xcConfirm("请输入联系电话");  
            } else {
                var phone = {
                    'phone': $('#phone').val()
                }
                $.ajax({
                    type: "POST",
                    url: 'http://m.3tmove.cn/3t-mobile-user/app/moveWebOrder/sendSms',
                    async: false,
                    contentType: 'application/json',
                    data: JSON.stringify(phone),
                    dataType: 'json',
                    success: function (res) {
                        if (res.code == 'ACK') {
                           
                            get_code_time(time); flag = false;
                        } else if (res.code == 'NACK') {
                          flag = true;
                          window.wxc.xcConfirm(res.message);  
                      }
                  }
              });
            }
        }
    })

 

posted @ 2018-01-30 17:09  是两页啊  阅读(167)  评论(0编辑  收藏  举报