溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

bootstrap3中dialog有什么用

發(fā)布時(shí)間:2021-08-13 10:05:16 來源:億速云 閱讀:137 作者:小新 欄目:web開發(fā)

這篇文章主要為大家展示了“bootstrap3中dialog有什么用”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“bootstrap3中dialog有什么用”這篇文章吧。

效果展示

1.error警告框

bootstrap3中dialog有什么用

2.confirm確認(rèn)選擇框

bootstrap3中dialog有什么用

3.Success提示框

bootstrap3中dialog有什么用

4.ajax加載遠(yuǎn)程頁面彈出框

bootstrap3中dialog有什么用

5.ajax加載自定義頁面彈出框

bootstrap3中dialog有什么用

三、使用方法

bootstrap3-dialog的demo中已有很詳細(xì)的介紹,但對(duì)于初學(xué)者來說是個(gè)麻煩,還要一個(gè)一個(gè)方法和注釋去看。但我對(duì)這些常用的方法進(jìn)行了新的封裝,所以就簡便了很多。
引入js和css文件我就不多說了,直接說使用方法。

①、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)日沒有資金日?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ì)話框以外的頁面內(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();
   }
  }
 });
};

通過$.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)程頁面彈出框

首先,我們先來看如何使用。

<a href="${ctx}/common/showSendMessage" rel="external nofollow" rel="external nofollow" target="dialog">點(diǎn)擊打開</a>

對(duì),就這一行代碼即可!

  1. 一個(gè)a標(biāo)簽

  2. 一個(gè)href屬性指向遠(yuǎn)程頁面

  3. target屬性設(shè)置為dialog

不過,我們需要做一下封裝。

第一步,頁面加載時(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);// 把傳回來的頁面作為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方法中增加對(duì)manipulating=1的處理。

if (manipulating == 1) {
 ajaxDialog = new BootstrapDialog({
  message : function(dialog) {
   var $message = $('<div></div>');
   $message.html(response);

   return $message;
  },
  // 找到自定義頁面上x號(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);// 無填充
 ajaxDialog.open();
}

以上是“bootstrap3中dialog有什么用”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI