dougou8573 2013-05-16 00:26
浏览 47
已采纳

如何摆脱不必要的JQuery弹出警报框

My code is as follows:

 function loadPage(url){
   $("#wrapper").load(url, function(){
        $("#wrapper").find($('a')).each(function(){
             $(this).on('click', function(e){
                loadPage($(this).attr('href'));
                e.preventDefault();
             });
        });
    });
}

 function JQueryAlert(message,windowHeight){
if (!windowHeight) var windowHeight = 470;

$("#msgdialog").remove();

$("body").append("<div id='msgdialog'></div>"); 

thatmsg = $("#msgdialog");

$("#msgdialog").dialog({
    resizable: false,
    draggable: false,
    width: 770,
    height: windowHeight,
    context: thatmsg,
    modal: true,
    autoOpen: false,
    buttons: {
        "Cancel" : function (){
            thatmsg.dialog("close");
        },
        "OK" : function (){
            loadPage("combat.php");
        }
    }
});     

$("#msgdialog").html(message);
$("#msgdialog").dialog('open');
}

$(document).ready(function() { JQueryAlert("HELLO!", 120); });

As you can see this displays a popup alert box, and upon the user clicking OK, it loads the file combat.php. Combat.php is simply a barebones php file that echoes some debug message like "Hello world!".

Now, my problem is, upon clicking OK and combat.php loading, the first popup goes away but up comes another popup. I can get rid of it by calling document.body.remove("#ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix"); in my combat.php, but this has the unwanted effect that "Hello World!" no longer displays. How do i get rid of this unwanted pop up???

Thanks for reading.

  • 写回答

1条回答 默认 最新

  • dream0776 2013-05-16 00:46
    关注

    Use:

        "OK" : function (){
            loadPage("combat.php");
            thatmsg.dialog("close");
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条