4

如何在dojo中创建确认对话框?我希望在按钮单击时出现一个确定取消对话框,使用 dojo 对话框(没有 javascript 确认对话框)。到目前为止,我只能在点击事件上显示一个对话框。这是我的代码:

<script type="text/javascript">
dojo.require("dijit.form.Button");
dojo.require("dijit.Dialog");

var secondDlg;
dojo.ready(function(){
    // create the dialog:
    secondDlg = new dijit.Dialog({
       title: "Programmatic Dialog Creation",
       style: "width: 300px",
   draggable:false
    });
});
showDialogTwo = function(){
   // set the content of the dialog:
   secondDlg.set("content", "Hey, I wasn't there before, I was added at " + new Date() + "!");
   secondDlg.show();
}
</script>
</head>
<body class="claro" style="margin-right:10px;">
<button id="buttonTwo" data-dojo-type="dijit.form.Button" data-dojo-props="onClick:showDialogTwo" type="button">Show me!</button>
</body>

我怎样才能使这个确定取消对话框?

4

3 回答 3

2
<script type="dojo/method" event="onClick">
                    var dialog = new dijit.Dialog({
                        title: "Delete Switch Type",
                        style: "width: 400px",
                        content : "Do you really want to delete ?????<br>"
                    });
                   //Creating div element inside dialog
                    var div = dojo.create('div', {}, dialog.containerNode);
                    dojo.style(dojo.byId(div), "float", "left");

                    var noBtn = new dijit.form.Button({
                                label: "Cancel",
                                onClick: function(){
                                    dialog.hide();
                                    dojo.destroy(dialog);
                                }
                             });

                    var yesBtn = new dijit.form.Button({
                                label: "Yes",
                                style : "width : 60px",
                                onClick : <your function here>,
                                dialog.hide();
                    dojo.destroy(dialog);
                                }
                             });
                                  //adding buttons to the div, created inside the dialog
                    dojo.create(yesBtn.domNode,{}, div);
                    dojo.create(noBtn.domNode,{}, div);
                    dialog.show();
                </script>

我将此代码用作内联 dojo/method - 在按钮的单击事件上。无论如何你都可以修改

于 2012-07-02T07:09:14.520 回答
2

从 Dojo 1.10 开始支持确认对话框。

请参阅发行说明文档

于 2014-12-11T08:33:12.057 回答
0

上面的解决方案没有考虑对话框右上角的小十字。

很久以前,我做了一套小对话框,你可能会在这里找到一些快乐,尤其是ConfirmDialog.js,我今天刚刚上传到github,你可以看看它们:http: //github.com/PEM- FR/Dojo-Components/tree/master/dojox/dialog

它们应该可以“按原样”使用或稍作改动

于 2012-07-03T07:06:02.727 回答