jquery外掛jquery.confirm彈出確認訊息
阿新 • • 發佈:2019-02-09
本文為大家介紹了外掛jquery.confirm彈出確認訊息的實現方法,具有一定的參考價值,特分享給大家供大家參考,具體內容如下
實現效果:
具體程式碼:
1、外掛預設引數
// 預設引數 $.confirm.defaults = { // 樣式 css: "http://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>
預設的外掛樣式基於css.3,預設的外掛樣式地址為default,外掛樣式只渲染一次,不會多次渲染,以第一次使用外掛的樣式為準。
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("你單擊了取消按鈕!"); } });
希望本文所述對大家學習jquery程式設計有所幫助。