2013-04-30 49 views
1

我想加载一个页面到jQueryUI的.dialog()功能,它工作正常。但关闭对话框后,我的页面的其余部分仍然被禁用。jQueryUI对话框正在打破我的页面

$(function() { 
    var w = $(document).width(); 
    var h = $(document).height(); 

    $("#diag").dialog({ //dialog box settings 
     autoOpen: false,  //do not open automatically 
     show: { 
      effect: "slide"  //slide frame in 
     }, 
     modal: true,   //disable the other elements 
     width: w,    //set width to window width 
     height: h    //set width to window height 
    }); 

    $(".icon").click(function() { //on .icon click 
     var v = $(this).attr('value'); //load value of clicked item into v 
     $("#diag").load(v).dialog("open"); //open the #diag box 
    }); 
}); 

当我带走.load(v)并注释掉V的初始化,.dialog()完美。我很难过。

+3

您正在加载的页面是否包含jQuery和jQuery UI的另一个副本? – 2013-04-30 20:24:43

+0

它没有。我把它包括进去了,重新测试了一下,让我更靠近了一步!现在回到主页面时,悬停工作。如果不刷新,我们仍然无法重新打开窗户。 – jrelwell 2013-04-30 20:30:39

回答

1

问题可能是因为.load异步替换了内容,所以您可能会丢失所有正确解除对话框的事件绑定。

试试这个:

var v = $(this).attr('value'); 
var dialogContent = $('#diag'); 
dialogContent.load(v, function() { 
    dialogContent.dialog('open'); 
}); 

换句话说,等待负载打开对话框之前完成。

+0

凯文的预感看起来很可能。 – Jacob 2013-04-30 20:28:49

+0

这是一个不行的:( 所以,我拉的按钮值是保存文件名,它是正确加载对话框,只是在关闭它之后,我必须刷新页面才能重新启动,打开刚刚关闭的同一对话框 – jrelwell 2013-04-30 20:36:11

+0

如何关闭对话框?也许问题在于该代码。 – Jacob 2013-04-30 20:36:51

0

将点击功能中的所有内容都移动到一切后,就可以正常工作。感谢大家的帮助。

$(function() { 
$(".icon").click(function() { //on .icon click 
    var w = $(document).width(); 
    var h = $(document).height(); 

    $("#diag").dialog({ //dialog box settings 
     show: { 
     effect: "slide"  //slide frame in 
     }, 
     modal: true,   //disable the other elements 
     width: w,   //set width to window width 
     height: h    //set width to window height 
}); 
    var v = $(this).attr('value'); //load value of clicked item into v 
$("#diag").load(v).dialog("open");  //open the #diag box 
}); 

});