bootstrap 模态框封装

/**
 * Created by xxh on 2018/2/13.
 */

var funSuccess = function () {}
var funCancel = function(){}

function clickOK() {
    funSuccess();
}
function clickCancel() {
    funCancel();
}
function showAlert(content, title, btnSuccessText, btnCancelText, success, cancel) {
    if(!title)
        title = '提示';
    if(!content) {
        content = '您确定要删除吗?';
    }
    if(!btnSuccessText) {
        btnSuccessText = "确定";
    }
    if(!btnCancelText) {
        btnCancelText = "取消";
    }
    if(success) {
        funSuccess = success;
    }
    if(cancel) {
        funCancel = cancel;
    }

    var modalHtml = '<!-- Modal -->\
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" \aria-labelledby="myModalLabel" data-backdrop="static">\
        <div class="modal-dialog" role="document">\
        <div class="modal-content">\
        <div class="modal-header">\
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>\
    <h4 class="modal-title" id="myModalLabel">'+title+'</h4>\
        </div>\
        <div class="modal-body">'+content+'</div>\
    <div class="modal-footer">\
        <button type="button" class="btn btn-default" data-dismiss="modal" onclick="clickCancel('+cancel+');">'+btnCancelText+'</button>\
        <button type="button" class="btn btn-primary" onclick="clickOK();">'+btnSuccessText+'</button>\
        </div>\
        </div>\
        </div>\
        </div>';
    $('body').append(modalHtml);
    $('#myModal').modal();
}

发表评论