這篇文章主要為大家展示了“bootstrap3中dialog有什么用”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“bootstrap3中dialog有什么用”這篇文章吧。
站在用戶的角度思考問題,與客戶深入溝通,找到墨江網(wǎng)站設(shè)計與墨江網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗,讓設(shè)計與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個性化、用戶體驗好的作品,建站類型包括:網(wǎng)站設(shè)計制作、成都做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣、域名申請、網(wǎng)站空間、企業(yè)郵箱。業(yè)務(wù)覆蓋墨江地區(qū)。
效果展示
1.error警告框
2.confirm確認選擇框
3.Success提示框
4.ajax加載遠程頁面彈出框
5.ajax加載自定義頁面彈出框
三、使用方法
bootstrap3-dialog的demo中已有很詳細的介紹,但對于初學(xué)者來說是個麻煩,還要一個一個方法和注釋去看。但我對這些常用的方法進行了新的封裝,所以就簡便了很多。
引入js和css文件我就不多說了,直接說使用方法。
①、error警告框
//彈出錯誤提示的登錄框 $.showErr = function(str, func) { // 調(diào)用show方法 BootstrapDialog.show({ type : BootstrapDialog.TYPE_DANGER, title : '錯誤 ', message : str, size : BootstrapDialog.SIZE_SMALL,//size為小,默認的對話框比較寬 buttons : [ {// 設(shè)置關(guān)閉按鈕 label : '關(guān)閉', action : function(dialogItself) { dialogItself.close(); } } ], // 對話框關(guān)閉時帶入callback方法 onhide : func }); };
這樣封裝后,需要彈出error警告框的時候直接使用$.showErr("當(dāng)日沒有資金日報")即可。
②、confirm確認選擇框
$.showConfirm = function(str, funcok, funcclose) { BootstrapDialog.confirm({ title : '確認', message : str, type : BootstrapDialog.TYPE_WARNING, // <-- Default value is // BootstrapDialog.TYPE_PRIMARY closable : true, // <-- Default value is false,點擊對話框以外的頁面內(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, // 對話框關(guān)閉的時候執(zhí)行方法 onhide : funcclose, callback : function(result) { // 點擊確定按鈕時,result為true if (result) { // 執(zhí)行方法 funcok.call(); } } }); };
通過$.showConfirm(title, _doPost);進行調(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(); } } ], // 指定時間內(nèi)可自動關(guān)閉 onshown : function(dialogRef) { setTimeout(function() { dialogRef.close(); }, YUNM._set.timeout); }, onhide : func }); };
④、ajax加載遠程頁面彈出框
首先,我們先來看如何使用。
<a href="${ctx}/common/showSendMessage" rel="external nofollow" rel="external nofollow" target="dialog">點擊打開</a>
對,就這一行代碼即可!
一個a標(biāo)簽
一個href屬性指向遠程頁面
target屬性設(shè)置為dialog
不過,我們需要做一下封裝。
第一步,頁面加載時,我們需要讓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);// 把傳回來的頁面作為message返回 return $message; }, title : title, } }); event.preventDefault(); return false; }); }, });
⑤、ajax加載自定義頁面彈出框
⑤和④類似,不過有些區(qū)別,下面只把區(qū)別列出來。
使用方法上,需要加上manipulating=”1”,指明為自定義頁面,不使用bootstrap dialog的header、footer。
<a href="${ctx}/common/showSendMessage" rel="external nofollow" rel="external nofollow" target="dialog" manipulating="1">自定義頁面</a>
ajaxTodialog方法中增加對manipulating=1的處理。
if (manipulating == 1) { ajaxDialog = new BootstrapDialog({ message : function(dialog) { var $message = $('<div></div>'); $message.html(response); return $message; }, // 找到自定義頁面上x號進行綁定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);// 無填充 ajaxDialog.open(); }
以上是“bootstrap3中dialog有什么用”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
網(wǎng)頁題目:bootstrap3中dialog有什么用
網(wǎng)站路徑:http://jinyejixie.com/article8/pocjip.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營銷、外貿(mào)建站、自適應(yīng)網(wǎng)站、網(wǎng)站內(nèi)鏈、網(wǎng)站導(dǎo)航、網(wǎng)站改版
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)