jQuery Mobile如何从弹出窗口打开另一个弹出窗口。

6
我正在使用PhoneGap上的jQuery mobile 1.9.1 min。 我有一个列表,其中每个项目点击后都会打开一个操作弹出窗口:
function showActions(index){
    selectedIndex = index; 
    $("#actionPopup").popup("open", {positionTo: '#list li:nth-child('+ index +')'});
}

<div data-role="popup" id="actionPopup" data-overlay-theme="a">
    <a href="#" data-rel="back" data-role="button" data-theme="a" data-icon="delete" data-iconpos="notext" class="ui-btn-right">Close</a>
        <ul data-role="listview">
                <li data-role="divider">Actions</li>
                <li data-icon="false" onclick="showDetails();">action1</li>
                <li data-icon="false">action2</li>
                <li data-icon="false">action3</li>
                <li data-icon="false">action4</li>
            </ul>
        </div>

当我按下使用showDetails()方法的action1时,该方法被调用,但第二个弹出窗口未显示。
function showDetails(){
    console.log("showDetails");
    $("#infoPopup").popup("open");
}

<div data-role="popup" id="infoPopup">
            <a href="#" data-rel="back" data-role="button" data-theme="a" data-icon="delete" data-iconpos="notext" class="ui-btn-right">Close</a>
            <div id="infoContent">
                <table>
                    <tr id="eventcode">
                        <td>test1:</td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr id="eventtype">
                        <td>test2:</td>
                        <td>&nbsp;</td>
                    </tr>
                </table>
            </div>
        </div>

我能做什么?

6个回答

11

我的解决方案

$.mobile.switchPopup = function(sourceElement, destinationElement, onswitched) {
    var afterClose = function() {
        destinationElement.popup("open");
        sourceElement.off("popupafterclose", afterClose);

        if (onswitched && typeof onswitched === "function"){
            onswitched();
        }
    };

    sourceElement.on("popupafterclose", afterClose);
    sourceElement.popup("close");
};

3
我使用以下简单函数来解决问题:
function myPopup(myPage) {
    history.back();
    setTimeout(function () {
        $(myPage).popup('open');
    }, 100);
}

3

@Rakoo的回答很好。这里有一个更简洁的版本:

$.mobile.switchPopup = function(sourceElement, destinationElement, onswitched) {
    sourceElement.one("popupafterclose", function() {
        destinationElement.popup("open")
        !onswitched || typeof onswitched !== "function" || onswitched()
    }).popup("close")
};

如果您不需要onswitched功能并且没有将其添加到$.mobile中,则可以这样简短而简单:
$('#popup1').one("popupafterclose", function(){$('#popup2').popup("open")}).popup("close")

1

我使用了这段代码来切换弹出窗口,它能正常工作。

function switchpop()
{
    $( '#popupMenu' ).popup( 'close' );  
    $( "#popupMenu" ).bind({popupafterclose: function(event, ui) 
            { 
                $( "#notes" ).popup( "open" );
            }
            });                
}

1

看起来弹出窗口的链接无法链接

解决方法:

$( document ).on( "pageinit", function() {
    $( '.popupParent' ).on({
        popupafterclose: function() {
            setTimeout( function(){ $( '.popupChild' ).popup( 'open' ) }, 100 );
        }
    });
});

0
经过四个小时的奋斗,我将问题简化为以下内容:
这是在第一个弹出窗口中的按钮单击函数。
    $('#popupCall').popup('close');

    window.setTimeout(function () { $('#popupContact').popup('open') }, 50);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接