bootstrap js创建模态框

Modal 属性

**m_系列——文字描述、内容类

//模态框抬头标题

Modal.m_title="string";

//模态框内容区域

Modal.m_body="string";//支持html对象

//模态框id

Modal.m_id="string";

**set_系列——执行函数类

//生成模态框底部按钮

Modal.set_btn({"string":callback})//按钮文字、执行函数

**基础系列

//弹出模态框

Modal.create()

//关闭模态框

Modal.close()

//模态框
function CreateModal(){
  this.m_title="默认模态框";
  this.m_body="默认内容";
  this.m_id="newmodal";
  this.m_target="body";
  this.btn=[];
  this.set_btn=function(data){
    var btnarr=[];
    for(var key in data){
      var btn = document.createElement("button");
      btn.className="btn btn-primary";
      btn.onclick=data[key];
      btn.innerHTML=key;
      this.btn.push(btn);
    }
  }
  this.close=function(){
    $(".modal.fade").remove();
    $(".modal-backdrop.fade").remove();
  }
  this.create=function(){
    this.close();
    var modal_block = document.createElement("div");
      modal_block.className = "modal fade";
      modal_block.id = this.m_id;
      modal_block.setAttribute("data-show","true")
      var modal_dialog = document.createElement("div");
        modal_dialog.className="modal-dialog modal-lg";
        var modal_content = document.createElement("div");
          modal_content.className="modal-content";
          var modal_head = document.createElement("div");
            modal_head.className=  "modal-header";
            var btn_close = document.createElement("button");
              btn_close.className="close";
              btn_close.type="button";
              btn_close.innerHTML="×";
              btn_close.addEventListener("click",this.close);
            modal_head.appendChild(btn_close);
            var modal_head_p = document.createElement("h4");
              modal_head_p.innerHTML=this.m_title;
            modal_head.appendChild(modal_head_p);
          modal_content.appendChild(modal_head);
          var modal_body = document.createElement("div");
            modal_body.className="modal_body";
            if(typeof(this.m_body)=="string"){
              modal_body.innerHTML=this.m_body;
            }else{
              modal_body.appendChild(this.m_body);
            }
          modal_content.appendChild(modal_body);
          var modal_footer =document.createElement("div");
            modal_footer.className="modal-footer";
            this.btn.map(function(btns,index){
              modal_footer.appendChild(btns);
            })
          modal_content.appendChild(modal_footer);
        modal_dialog.appendChild(modal_content);
      modal_block.appendChild(modal_dialog);

    $(this.m_target).append(modal_block);
    $("#"+this.m_id).modal('show');
  }
}