亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

bootstrap3 dialog 更強(qiáng)大、更靈活的模態(tài)框

 更新時(shí)間:2017年04月20日 09:17:49   作者:沉默王二  
這篇文章主要介紹了bootstrap3 dialog 更強(qiáng)大、更靈活的模態(tài)框,本文通過(guò)效果展示實(shí)例代碼詳解,需要的朋友可以參考下

用過(guò)bootstrap框架的同學(xué)們都知道,bootstrap自帶的模態(tài)框用起來(lái)很不靈活,可謂雞肋的很。但nakupanda開(kāi)源作者封裝了一個(gè)更強(qiáng)大、更靈活的模態(tài)框——bootstrap3-dialog。

一、源碼下載

bootstrap3-dialog git下載地址

二、效果展示

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ì),就這一行代碼即可!

  1. 一個(gè)a標(biāo)簽
  2. 一個(gè)href屬性指向遠(yuǎn)程頁(yè)面
  3. 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)站的支持!

相關(guān)文章

最新評(píng)論