Jquery对话框多个打开



我有那个url:

<a onClick="showDialog({$product['id']});">More Info...</a>

另外我还有:

function showDialog(productID)
{
    $( "#dialog-modal_"+productID ).html( "<iframe src='index.php?act=showProduct&amp;id="+productID+"' width='100%' height='100%' frameborder='0' scrolling='no'></iframe>" );
    $( "#dialog-modal_"+productID ).dialog({
    width: 810,
    height: 590,
    resizable: false,
    modal: true,
    open: function(event, ui)
    {
        event.preventDefault();
    }
    });
    container
        .dialog('option', 'title', 'Your Title')
        .dialog('option', 'buttons', {
            Close: function() {
                $(this).dialog('close');
            }
        })
        .dialog('open');
    var stateObj = { foo: "bar" };
    window.history.pushState(stateObj, "page 2", "{$info['siteurl']}/index.html#product-"+productID);
}

如果我打开它一次,它工作,但如果我再试一次,它没有打开。我需要找到一种方法来"清除"当前ID的最后一个对话框。

产品循环内部:

<a href="javascript:" class="productOpener" data-id="{$product['id']}">more info...</a>

和你的javascript:

$(".productOpener").click(function() {
    showDialog($(this).data("id"));
});

修改你的showDialog,在你需要的时候创建模态div:

function showDialog(productID) {
    var _modal = $("<div/>"); //add whatever styling you need
    _modal.html( "<iframe src='index.php?act=showProduct&amp;id="+productID+"' width='100%' height='100%' frameborder='0' scrolling='no'></iframe>" );
    _modal.dialog({ ... });
    ...
}

最新更新