bootstrap3 dialog 更強(qiáng)大、更靈活的模態(tài)框
用過(guò)bootstrap框架的同學(xué)們都知道,bootstrap自帶的模態(tài)框用起來(lái)很不靈活,可謂雞肋的很。但nakupanda開(kāi)源作者封裝了一個(gè)更強(qiáng)大、更靈活的模態(tài)框——bootstrap3-dialog。
一、源碼下載
二、效果展示
1.error警告框
2.confirm確認(rèn)選擇框
3.Success提示框
4.ajax加載遠(yuǎn)程頁(yè)面彈出框
5.ajax加載自定義頁(yè)面彈出框
三、使用方法
bootstrap3-dialog的demo中已有很詳細(xì)的介紹,但對(duì)于初學(xué)者來(lái)說(shuō)是個(gè)麻煩,還要一個(gè)一個(gè)方法和注釋去看。但我對(duì)這些常用的方法進(jìn)行了新的封裝,所以就簡(jiǎn)便了很多。
引入js和css文件我就不多說(shuō)了,直接說(shuō)使用方法。
①、error警告框
//彈出錯(cuò)誤提示的登錄框 $.showErr = function(str, func) { // 調(diào)用show方法 BootstrapDialog.show({ type : BootstrapDialog.TYPE_DANGER, title : '錯(cuò)誤 ', message : str, size : BootstrapDialog.SIZE_SMALL,//size為小,默認(rèn)的對(duì)話框比較寬 buttons : [ {// 設(shè)置關(guān)閉按鈕 label : '關(guān)閉', action : function(dialogItself) { dialogItself.close(); } } ], // 對(duì)話框關(guān)閉時(shí)帶入callback方法 onhide : func }); };
這樣封裝后,需要彈出error警告框的時(shí)候直接使用$.showErr("當(dāng)日沒(méi)有資金日?qǐng)?bào)")即可。
②、confirm確認(rèn)選擇框
$.showConfirm = function(str, funcok, funcclose) { BootstrapDialog.confirm({ title : '確認(rèn)', message : str, type : BootstrapDialog.TYPE_WARNING, // <-- Default value is // BootstrapDialog.TYPE_PRIMARY closable : true, // <-- Default value is false,點(diǎn)擊對(duì)話框以外的頁(yè)面內(nèi)容可關(guān)閉 draggable : true, // <-- Default value is false,可拖拽 btnCancelLabel : '取消', // <-- Default value is 'Cancel', btnOKLabel : '確定', // <-- Default value is 'OK', btnOKClass : 'btn-warning', // <-- If you didn't specify it, dialog type size : BootstrapDialog.SIZE_SMALL, // 對(duì)話框關(guān)閉的時(shí)候執(zhí)行方法 onhide : funcclose, callback : function(result) { // 點(diǎn)擊確定按鈕時(shí),result為true if (result) { // 執(zhí)行方法 funcok.call(); } } }); };
通過(guò)$.showConfirm(title, _doPost);進(jìn)行調(diào)用。
③、Success提示框
$.showSuccessTimeout = function(str, func) { BootstrapDialog.show({ type : BootstrapDialog.TYPE_SUCCESS, title : '成功 ', message : str, size : BootstrapDialog.SIZE_SMALL, buttons : [ { label : '確定', action : function(dialogItself) { dialogItself.close(); } } ], // 指定時(shí)間內(nèi)可自動(dòng)關(guān)閉 onshown : function(dialogRef) { setTimeout(function() { dialogRef.close(); }, YUNM._set.timeout); }, onhide : func }); };
④、ajax加載遠(yuǎn)程頁(yè)面彈出框
首先,我們先來(lái)看如何使用。
<a href="${ctx}/common/showSendMessage" rel="external nofollow" rel="external nofollow" target="dialog">點(diǎn)擊打開(kāi)</a>
對(duì),就這一行代碼即可!
- 一個(gè)a標(biāo)簽
- 一個(gè)href屬性指向遠(yuǎn)程頁(yè)面
- target屬性設(shè)置為dialog
不過(guò),我們需要做一下封裝。
第一步,頁(yè)面加載時(shí),我們需要讓a標(biāo)簽執(zhí)行ajaxTodialog方法。
$(function() { // dialogs if ($.fn.ajaxTodialog) { $("a[target=dialog]").ajaxTodialog(); } });
第二步,封裝ajaxTodialog方法。
$.fn.extend({ ajaxTodialog : function() { return this.click(function(event) { var $this = $(this); YUNM.debug("ajaxTodialog" + $this.selector); var title = $this.attr("title") || $this.text(); var url=$this.attr("href"); $.ajax({ type : 'POST', url : url, cache : false, success : function(response) { ajaxDialog = BootstrapDialog.show({ message : function(dialog) { var $message = $('<div></div>'); $message.html(response);// 把傳回來(lái)的頁(yè)面作為message返回 return $message; }, title : title, } }); event.preventDefault(); return false; }); }, });
⑤、ajax加載自定義頁(yè)面彈出框
⑤和④類似,不過(guò)有些區(qū)別,下面只把區(qū)別列出來(lái)。
使用方法上,需要加上manipulating=”1”,指明為自定義頁(yè)面,不使用bootstrap dialog的header、footer。
<a href="${ctx}/common/showSendMessage" rel="external nofollow" rel="external nofollow" target="dialog" manipulating="1">自定義頁(yè)面</a>
ajaxTodialog方法中增加對(duì)manipulating=1的處理。
if (manipulating == 1) { ajaxDialog = new BootstrapDialog({ message : function(dialog) { var $message = $('<div></div>'); $message.html(response); return $message; }, // 找到自定義頁(yè)面上x(chóng)號(hào)進(jìn)行綁定close事件 onshown : function(dialogRef) { var $button = dialogRef.getModalContent().find('button[data-widget="remove"]'); $button.on('click', { dialogRef : dialogRef }, function(event) { event.data.dialogRef.close(); }); }, }); ajaxDialog.realize(); ajaxDialog.getModalHeader().hide();// header不要 ajaxDialog.getModalFooter().hide();// footer也不要 ajaxDialog.getModalBody().css('padding', 0);// 無(wú)填充 ajaxDialog.open(); }
以上所述是小編給大家介紹的bootstrap3 dialog 更強(qiáng)大、更靈活的模態(tài)框,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
- 淺析BootStrap中Modal(模態(tài)框)使用心得
- Bootstrap模態(tài)框(modal)垂直居中的實(shí)例代碼
- Bootstrap每天必學(xué)之模態(tài)框(Modal)插件
- BOOTSTRAP時(shí)間控件顯示在模態(tài)框下面的bug修復(fù)
- 頁(yè)面遮罩層,并且阻止頁(yè)面body滾動(dòng)。bootstrap模態(tài)框原理
- Bootstrap BootstrapDialog使用詳解
- BootStrap+Angularjs+NgDialog實(shí)現(xiàn)模式對(duì)話框
- 封裝的dialog插件 基于bootstrap模態(tài)對(duì)話框的簡(jiǎn)單擴(kuò)展
相關(guān)文章
JavaScript彈出新窗口并控制窗口移動(dòng)到指定位置的方法
這篇文章主要介紹了JavaScript彈出新窗口并控制窗口移動(dòng)到指定位置的方法,涉及javascript針對(duì)彈出窗口的操作技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-04-04JS賦值、淺拷貝和深拷貝(數(shù)組和對(duì)象的深淺拷貝)實(shí)例詳解
這篇文章主要介紹了JS賦值、淺拷貝和深拷貝,結(jié)合實(shí)例形式總結(jié)分析了JavaScript數(shù)組和對(duì)象的深淺拷貝相關(guān)概念、原理、操作技巧與使用注意事項(xiàng),需要的朋友可以參考下2020-03-03js實(shí)現(xiàn)文本框支持加減運(yùn)算的方法
這篇文章主要介紹了js實(shí)現(xiàn)文本框支持加減運(yùn)算的方法,可實(shí)現(xiàn)文本框輸入加減運(yùn)算式同時(shí)右側(cè)實(shí)時(shí)顯示對(duì)應(yīng)計(jì)算結(jié)果的功能,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-08-08js實(shí)現(xiàn)計(jì)算器和計(jì)時(shí)器功能
這篇文章主要為大家詳細(xì)介紹了js實(shí)現(xiàn)計(jì)算器和計(jì)時(shí)器功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-07-07js實(shí)現(xiàn)無(wú)縫滾動(dòng)圖
本文主要分享了js實(shí)現(xiàn)無(wú)縫滾動(dòng)圖的示例代碼,具有很好的參考價(jià)值,下面跟著小編一起來(lái)看下吧2017-02-02