jQuery Jquery对话框打开另一个页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2756283/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 14:12:31  来源:igfitidea点击:

Jquery dialog to open another page

jqueryjquery-uijquery-pluginsjquery-dialog

提问by Hulk

There is a page as transaction.html

有一个页面为 transaction.html

How to open this page in a popup in another page say show_transactions.html in a jquery dialog

如何在另一个页面的弹出窗口中打开此页面在 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');

This code is present in show_transactions.html

此代码存在于 show_transactions.html

Thanks..

谢谢..

回答by Zack

You can use jQuery's .load()method to load a page into a dialog, here's how:

您可以使用 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");
    });
})

This assumes the dialog has an ID of 'dialog' and that there's another element with ID of 'dialog_trigger' that is clicked to open it. You'd put both of these into your document's ready function so that the dialog is made on page-load, if it isn't, it will cause a slight-but-noticeable delay for the user as it's made.

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

回答by Joanne

You can also do like this...

你也可以这样做...

Create dialog page

创建对话页面

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

Create a link(when we click on that link it will open the dialog)

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

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

Initialise the dialog(create an event between the link and the dialog)

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

$('#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;
            });
    });
});