DIV CSS 佈局教程網

使用 jquery.confirm 外掛彈出確認訊息視窗
編輯:關於JavaScript     

本文為大家介紹 jquery.confirm 外掛彈出確認訊息視窗的實作方法,具備一定參考價值,具體內容如下。

實作效果:

具體程式碼:

1、外掛預設參數

 // 默認參數 $.confirm.defaults = { // 樣式 css: "https://static.qianduanblog.com/css/jquery.confirm/default.min.css?v=" + Math.ceil(new Date() / 86400000), // 確認框內容 content: "確認嗎?", // 確認按鈕文字 sureButton: "確認", // 取消按鈕文字 cancelButton: "取消", // 位置 position: {}, // 自動打開 autoOpen: false, // 動畫持續時間 duration: 123, // 打開確認框回調 onopen: emptyFn, // 單擊了確認或者取消回調 onclick: emptyFn, // 確認回調 onsure: emptyFn, // 取消回調 oncancel: emptyFn, // 關閉確認框回調 onclose: emptyFn }

2、外掛結構與樣式

jquery.confirm 的 DOM 結構如下:

 <div class="jquery_confirm____" style="display:none"> <div class="jquery_confirm____body">確認框消息</div> <div class="jquery_confirm____footer"> <button class="button button-primary jquery_confirm____sure">確認</button> <button class="button button-error jquery_confirm____cancel">取消</button> </div> </div>

預設的外掛樣式基於 CSS3,且樣式只會渲染一次、不會重複,以第一次使用外掛的樣式為準。

3、使用方法

 // 打開確認框 $.confirm({ content: "確認要查看嗎?", onopen: function() { alert("確認框打開了!"); }, onclose: function() { alert("確認框關閉了!"); }, onsure: function() { alert("你單擊了確認按鈕!"); }, oncancel: function() { alert("你單擊了取消按鈕!"); }, onclick: function(s) { if (s) { alert("你單擊了確認按鈕!"); } else { alert("你單擊了取消按鈕!"); } } }); $.confirm("確認嗎?", function(s) { if (s) { alert("你單擊了確認按鈕!"); } else { alert("你單擊了取消按鈕!"); } }); 

透過豐富的回調函式(onopen、onclose、onsure、oncancel、onclick),這個外掛能靈活處理確認框在開啟、關閉與點擊時的各種互動。

希望本文所述的內容能對大家學習 jQuery 有所幫助。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved