Jquery dialog to open another page

情到浓时终转凉″ 提交于 2020-01-12 08:29:10

问题


There is a page as transaction.html

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

       $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

Thanks..


回答1:


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

$("#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.




回答2:


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;
            });
    });
});


来源:https://stackoverflow.com/questions/2756283/jquery-dialog-to-open-another-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!