利用回调函数实现的一个简单确认对话框。

说明一下:如下采用IFRAME子调顶的方式进行对话框的获取(内页弹出提示请求,顶层窗体做统一弹出请求),因为仅做了技术上的实现,关于页面及详细代码如果需要请自行补脑。如果需要遮罩什么的处理也请自行补脑。

另外如果对回调函数不理解请自行查阅相关文档。

顶窗体:

<html>
<head>
<title>Com.unisi.YPB</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script    src="jquery-1.8.3.min.js" type="text/javascript"></script>
<script>
$.extend($.fx,{message:{}})
$.extend($.fx.message,
{
    confirm:function(callBack){
        var call = new callBack();
        if ($("#fx-uc-dialog-confirm").length > 0) {
            $("#fx-uc-dialog-confirm").click(function(){
                call.confirm();
            });
        }
        if ($("#fx-uc-dialog-cancel").length > 0) {
            $("#fx-uc-dialog-cancel").click(function(){
                call.cancel();
            });
        }
        
    }
})
</script>
</head>
<body>
<style>
.dialogs{200px;background:#000;height:100px;}
.dialogs span{background:#fff;color:#000;50px;height:20px;display:block;float:left;margin-left:10px;}
</style>
<div class="dialogs"><span id="fx-uc-dialog-confirm">是</span><span id="fx-uc-dialog-cancel">否</span></div>
<iframe id="fx-frm" name="frm" src="b.html" width="1000px" height="500px" frameborder="1" scrolling="auto"></iframe>
</body>
</html>

子窗体:

<html>
<head>
<title>Com.unisi.YPB</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script    src="/com.unisi.client.core.ent.csm/component-script/libs-lib/jquery-1.8.3.min.js" type="text/javascript"></script>
<script>
window.top.$.fx.message.confirm(deletePrompt);

function deletePrompt() {
    this.confirm = function () {alert("选择了确认");}/*此部分如果需要自定义代码可以补充在这里面*/
    this.cancel = function () {alert("选择了取消");}
}
</script>
</head>
<body>
</body>
</html>
原文地址:https://www.cnblogs.com/fan-yuan/p/5079933.html