//用例
var dlg = this._ynDlg;
if (!dlg) {
dlg = this._ynDlg = new DialogYesNo({
whenYes: function () {alert("yes"); }
});
}
dlg.show("确认删除子账户吗?");
});
//源代码
//DialogYesNo.js
define([
"dojo/_base/declare",
"dijit/Dialog",
"dijit/_WidgetsInTemplateMixin",
"dojo/text!./templates/DialogYesNo.html",
"dijit/form/Button"
],function (declare,Dialog,_WidgetsInTemplateMixin,template) {
return declare([Dialog,_WidgetsInTemplateMixin],{
baseClass: "DialogYN",
templateString: template,
title: "确认",
whenNo: function () {
},
_no: function () {
this.hide();
this.whenNo();
},
whenYes: function () {
},
_yes: function () {
this.hide();
this.whenYes();
},
_keydown: function (event) {
var key = event.keyCode;
if (key === 78)
this._no();
else if (key === 89)
this._yes();
},
show: function (content) {
this.set("content",content);
this.inherited(arguments);
}
});
});
//./templates/DialogYesNo.html
<div class="dijitDialog" role="dialog" aria-labelledby="${id}_title"> <div data-dojo-attach-point="titleBar" class="dijitDialogTitleBar"> <span data-dojo-attach-point="titleNode" class="dijitDialogTitle" id="${id}_title" role="heading" level="1"></span> <span data-dojo-attach-point="closeButtonNode" class="dijitDialogCloseIcon" data-dojo-attach-event="ondijitclick: onCancel,keydown:_keydown" title="${buttonCancel}" role="button" tabIndex="-1"> <span data-dojo-attach-point="closeText" class="closeText" title="${buttonCancel}">x</span> </span> </div> <div data-dojo-attach-point="containerNode" class="dijitDialogPaneContent"> </div> <div style="background-color:#ffffff;min-width: 200px;height: 40px"> <div data-dojo-attach-point="buttonContainer" style="float: right;margin-right: 20px"> <button data-dojo-type="dijit/form/Button" data-dojo-attach-point="btnYes" data-dojo-attach-event="onClick:_yes">是(Y) </button> <button data-dojo-type="dijit/form/Button" data-dojo-attach-point="btnNo" data-dojo-attach-event="onClick:_no">否(N) </button> </div> </div> </div>
原文链接:https://www.f2er.com/dojo/291372.html