Jquery对话框打开另一个页面

时间:2010-05-03 05:32:30

标签: jquery jquery-ui jquery-plugins jquery-dialog

有一个页面为transaction.html

如何在另一个页面的弹出窗口中打开此页面,在jquery对话框中说show_transactions.html

       $dialog.html()  //open transaction.html in this dialog
     .dialog({
        autoOpen: true,
        position: 'center' ,
        title: 'EDIT',
        draggable: false,
        width : 300,
        height : 40, 
        resizable : false,
        modal : true,
     });
     alert('here');
     $dialog.dialog('open');

此代码显示在show_transactions.html

谢谢..

2 个答案:

答案 0 :(得分:15)

您可以使用jQuery的.load()方法将页面加载到对话框中,具体如下:

$("#dialog").dialog({
    autoOpen: false,
    position: 'center' ,
    title: 'EDIT',
    draggable: false,
    width : 300,
    height : 40, 
    resizable : false,
    modal : true,
});

$("#dialog_trigger").click( function() {
    $("#dialog").load('path/to/file.html', function() {
        $("#dialog").dialog("open");
    });
})

这假设对话框的ID为'dialog',并且有另一个ID为'dialog_trigger'的元素被单击以打开它。你可以将这两个文件放入文档的就绪函数中,以便在页面加载时进行对话,如果不是,则会对用户造成轻微但明显的延迟。

答案 1 :(得分:3)

你也可以这样做......

创建对话框页

<div id="MyDialogID"  title="My Dialog Title"></div>

创建链接(当我们点击该链接时,它会打开对话框)

<a id="MyLinkToDialogID" href="Path to Dialog Page">Open My Dialog</a>

初始化对话框(在链接和对话框之间创建一个事件)

$('#MyLinkToDialogID').each(function () {
    var $link = $(this);

    $.post($link.attr('href'), function (data) {
        var $dialog = $(data)
            .filter('#MyDialogID')
            .dialog({
                autoOpen: false,
                resizable: false,
                height: 240,
                width: 370,
                modal: true
            });

            $link.click(function () {
               $dialog.dialog("open");
               $dialog.css("height", "240");
               $dialog.css("width", "370px");
               $dialog.dialog({ position: 'center' });

               return false;
            });
    });
});
相关问题