国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

擴展bootstrap的modal模態框-動態添加modal框-彈出多個modal框

2019-11-19 17:28:23
字體:
來源:轉載
供稿:網友

js代碼

function initView(_box){   var $p = $(_box || document);   $('a[target="dialog"]', $p).each(function(event){     $(this, $p).unbind('click').click(function(event){       openModal(event);     });   }); } $(function(){   initView(); }); /**關閉modal*/ function hideModal(obj){   var modal = $(obj).parents("div.modal");   if(modal.length > 0){     modal.remove();     initView();   } } /**打開modal*/ function openModal(event){ // var this = $(this);   var $this = $(event.currentTarget);   var _url = $this.attr("href");   var _title = $this.attr("title");   var _id;   _id = dialog.content();   var options = {       backdrop: false,       keyboard: true,       show: true   };   $('#' + _id).modal(options);   var modal = $('#' + _id);   if(typeof(_title) != "undefined"){      if(modal.find('.modal-title').length <= 0){        var header = dialog.header({title : _title});        $($.parseHTML(header)).appendTo(modal.find(".modal-content"));      }else{        modal.find('.modal-title').text(_title);      }      if(modal.find('.modal-body').length <= 0){        var _body = dialog.body;        $($.parseHTML(_body)).appendTo(modal.find(".modal-content"));      }      modal.find(".modal-body").load(_url, $.proxy(function () {        modal.trigger('loaded.bs.modal');        initView();       }, this));    }else{      modal.find(".modal-content").load(_url, $.proxy(function () {        modal.trigger('loaded.bs.modal');        initView();       }, this));    }     //阻止事件默認行為   event.preventDefault(); } //modal model //TO STRAT if(!$(window).data("_modal_id")){   $(window).data("_modal_id", 0); } var dialog = {   header : function(options){     var template = '<div class="modal-header">'             +  '<button type="button" class="close" aria-label="Close" onclick="hideModal(this);"><span aria-hidden="true">×</span></button>'             +  '<h4 class="modal-title">' + options.title + '</h4>'             +'</div>';     return template;   },   content : function(){     var _modal_id = $(window).data("_modal_id");     var _id = "_modal_id_" + _modal_id;     _modal_id ++;     $(window).data("_modal_id", _modal_id);     var template = '<div class="modal fade" tabindex="-1" role="dialog" id="'+ _id +'">'      +  '<div class="modal-dialog modal-lg" role="document" aria-hidden="true">'      +   '<div class="modal-content">'      +   '</div>'      +  '</div>'      +'</div>';     $(template).appendTo('body');     initView();     return _id;   },   body : '<div class="modal-body"></div>' }; //TO END 

頁面代碼:

<a href="select.html" rel="external nofollow" id="signId" class="btn btn-info" <span style="background-color: rgb(255, 255, 102);">target="dialog"</span> title="請選擇用餐類型">簽到</a> 

頁面上只要在a標簽后加上target="dialog",并且提供href外部鏈接地址就可以彈出modal框

以上所述是小編給大家介紹的擴展bootstrap的modal模態框-動態添加modal框-彈出多個modal框,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 上饶市| 阳高县| 安泽县| 大英县| 丰台区| 宁城县| 洛宁县| 巴林左旗| 昭苏县| 乐昌市| 田东县| 平凉市| 通辽市| 安岳县| 泸州市| 南宁市| 德保县| 江山市| 盘锦市| 肃北| 墨竹工卡县| 福安市| 藁城市| 左贡县| 和林格尔县| 桂东县| 宕昌县| 清苑县| 凤凰县| 屯昌县| 黄冈市| 定远县| 含山县| 南乐县| 祁门县| 阿拉善盟| 龙泉市| 淮南市| 开江县| 清涧县| 高密市|