组件化bootstrap模态窗

今天遇到家长开通视频日期展示的问题,封装了bootstrap原生modal

!(function (window, $, undefined) {

    var messageModal = function (opt) {
        var defaults = {
            title: '查看详情',
            bodyText: '....',
            titleCss: {"fontSize": "16px", "text-align": "center"},
            bodyCss: {"fontSize": "12px", "text-align": "center"}
        }
        this.options = $.extend({}, defaults, opt);

        this.pbody = $(parent.body);

    }

    var html = {
        patentd: '<div class="modal message-modal-see" id="myModal"  style="display: block;background:rgba(0,0,0,0.2);"></div>',
        modalDialog: '<div class="modal-dialog" role="document"></div>',
        modalContent: '<div class="modal-content"></div>',
        modalHead: '<div class="modal-header"></div>',
        headBtn: '<button type="button" class="close close-modal" ><span aria-hidden="true">×</span></button>',
        headTitle: '<h4 class="modal-title" id="myModalLabel" style="text-align: center">视频开通详情</h4>',
        modalBody: ' <div class="modal-body"></div>',
        modalFooter: ' <div class="modal-footer"></div>',
        footerCbtn: ' <button type="button" class="btn btn-default close-modal" data-dismiss="modal">关闭</button>',

    }
    var fatherBody = $(window.top.document.body);
    messageModal.prototype = {
        createModal: function (ele) {
            $(html.headTitle).text(this.options.title).css(this.options.titleCss);
            var mobody = $(html.modalBody).css(this.options.bodyCss).append(this.options.bodyText);
            var content = $(html.modalContent).append(
                $(html.modalHead).append(html.headBtn).append($(html.headTitle))
            ).append(
                mobody
            ).append(
                $(html.modalFooter).append(html.footerCbtn)
            ).css('margin-top', '60%')

            var modal = $(html.patentd).append(
                $(html.modalDialog).append(
                    content
                )
            )

            modal.appendTo(fatherBody)
        },
        removeModal: function () {
            this.remove()
        },
    }

    $(parent.document).on('click', '.close-modal',  function () {
        $(parent.document).find('.message-modal-see').remove()
    });
    window.messageModal = messageModal
}(window, jQuery));


使用


                   <td data-studnet-times="${student.times}">
                            <c:if test="${fn:length(student.times)>1}">
                                ${fn:substring(student.times,1,22)}
                                <c:if test="${fn:length(student.times)>1}">
                                    <button class="btn  btn-info btn-xs see-more-times">查看更多</button>
                                </c:if>
                            </c:if>
                            <c:if test="${fn:length(student.times)==1}">
                                ${student.times}
                            </c:if>
                        </td>




$('.see-more-times').click(function (e) {
        var self = this;
        var dataTimes = $(self).parents('td').data('studnet-times');
        var data = dataTimes.substr(1, dataTimes.length - 2).replace(/—/g, '到').replace(/,/g, '</br>');
        var modal = new messageModal({
            bodyText: data,
            bodyCss: {"fontSize": "20px", "text-align": "center"}
        });
        modal.createModal()
    });

效果

image.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,287评论 25 708
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,232评论 4 61
  • 希望考试过过过
    Missong阅读 157评论 0 0
  • 阅读完《好好说话》,发现说话能不能说清楚、说得有力量,是有策略可循的。其实是关于在说话前思维清不清晰、嘴巴能不能跟...
    八er阅读 489评论 2 1
  • 很多年轻人,现在最关心的话题就是:减肥。吃货们每天都叫苦连天的嚷嚷要减肥,之后依旧该吃吃,该喝喝。管不住嘴,迈不开...
    风花星月阅读 598评论 8 4