擴(kuò)展bootstrap的modal模態(tài)框-動(dòng)態(tài)添加modal框-彈出多個(gè)modal框
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(); }); /**關(guān)閉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)); } //阻止事件默認(rèn)行為 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
頁(yè)面代碼:
<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="請(qǐng)選擇用餐類型">簽到</a>
頁(yè)面上只要在a標(biāo)簽后加上target="dialog",并且提供href外部鏈接地址就可以彈出modal框
以上所述是小編給大家介紹的擴(kuò)展bootstrap的modal模態(tài)框-動(dòng)態(tài)添加modal框-彈出多個(gè)modal框,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
- 在iframe中使bootstrap的模態(tài)框在父頁(yè)面彈出問題
- Bootstrap彈出框之自定義懸??驑?biāo)題、內(nèi)容和樣式示例代碼
- Bootstrap的popover(彈出框)2秒后定時(shí)消失的實(shí)現(xiàn)代碼
- Bootstrap實(shí)現(xiàn)提示框和彈出框效果
- Bootstrap實(shí)現(xiàn)帶動(dòng)畫過渡的彈出框
- Bootstrap編寫一個(gè)在當(dāng)前網(wǎng)頁(yè)彈出可關(guān)閉的對(duì)話框 非彈窗
- Bootstrap彈出框(modal)垂直居中的問題及解決方案詳解
- 關(guān)于Bootstrap彈出框無(wú)法調(diào)用問題的解決辦法
- JS組件Bootstrap實(shí)現(xiàn)彈出框和提示框效果代碼
- bootstrap實(shí)現(xiàn)點(diǎn)擊刪除按鈕彈出確認(rèn)框的實(shí)例代碼
相關(guān)文章
JavaScript switch case 的用法實(shí)例[范圍]
JavaScript switch case 的用法實(shí)例,大家可以參考下。2009-09-09echarts tooltip自適應(yīng)寬高讓提示框適應(yīng)不同屏幕尺寸demo
這篇文章主要為大家介紹了echarts tooltip自適應(yīng)寬高讓提示框適應(yīng)不同屏幕尺寸,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-10-10javascript 拖動(dòng)表格行實(shí)現(xiàn)代碼
用js實(shí)現(xiàn)的拖動(dòng)表格的tr行的實(shí)現(xiàn)代碼,需要的朋友可以參考下。2011-05-05原生js實(shí)現(xiàn)水平方向無(wú)縫滾動(dòng)
這篇文章主要為大家詳細(xì)介紹了原生js實(shí)現(xiàn)水平方向無(wú)縫滾動(dòng)的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-01-01js日期插件dateHelp獲取本月、三個(gè)月、今年的日期
這篇文章主要為大家詳細(xì)介紹了js日期插件dateHelp獲取本月、三個(gè)月、今年的日期,感興趣的小伙伴們可以參考一下2016-03-03