美文网首页
showMessage 弹框函数

showMessage 弹框函数

作者: TonyYu | 来源:发表于2016-07-14 13:47 被阅读0次
     /** 
        * @param {msg} 弹框信息内容 
        * @param {autoclose} 几秒后自动关闭 默认为3秒
        * @param {iscancel} 是否是选择框 
        * @param {okcb} 成功后执行回调函数 
        * @param {cancelcb} 取消后执行回调函数 
    */
    function showMessage(msg, autoClose, isCancel, okCb, cancelCb){
        var mThis = $('#openBox'); 
        var isShow = mThis.data('isShow'); 
        if(isShow)return; 
        mThis.show(); 
        mThis.data('isShow', true); 
        var s = typeof autoClose == 'number'?autoClose:3; 
        if(autoClose){
            var st = setInterval(function(){
                s--;
                if(s > 0){
                    $('#openBox_auto').html(s+'秒后自动关闭');
                } else {
                    hideMessage(okCb);
                }
            }, 1000);
        }
        $('#openBox_txt').html(msg); 
        if(autoClose)
            $('#openBox_auto').html(s+'秒后自动关闭');
        else
            $('#openBox_auto').html('');
        if(isCancel){
            $('#openBox_cancel').show();
        } else {
            $('#openBox_cancel').hide();
        }
        function hideMessage(cb){  
            if(autoClose && st) 
                clearInterval(st);
            mThis.hide();
            mThis.data('isShow', false);
            if(cb != undefined && typeof cb == 'function'){
                cb(); 
            }
        }
        $('#openBox_ok').click(function(){
            hideMessage(okCb);
            $('#openBox_cancel').unbind('click');
            $(this).unbind('click');
            return false;
        });
        $('#openBox_cancel').click(function(){
            hideMessage(cancelCb);
            $('#openBox_ok').unbind('click');
            $(this).unbind('click');
            return false;
        });
    
        $(document).keydown(function(event){
            $('.inputThis').removeClass('inputThis');
            var box = $('.merchant_popbox');
            var inp = $('input:focus').addClass('inputThis');
            if(box.css("display")=='block'){
                if (event.keyCode == 13){
                    box.fadeOut(200,function(){
                        inp.focus();
                    })
                    $('input').blur();
                    $('#openBox_ok').click();
                }
            }
        })
    }
    

    相关文章

      网友评论

          本文标题:showMessage 弹框函数

          本文链接:https://www.haomeiwen.com/subject/aqvejttx.html