6

1.9.1 min在PhoneGap 上使用jQuery 移动。
我有一个列表,其中每个单击项都会打开一个操作弹出窗口:

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>

当我用它们按下 action1 时,showDetails()方法被调用,但第二个弹出窗口没有显示。

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>

我能做些什么?

4

6 回答 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");
};
于 2014-03-22T21:17:09.657 回答
3

I used this simple function for the work-around:

function myPopup(myPage) {
    history.back();
    setTimeout(function () {
        $(myPage).popup('open');
    }, 100);
}
于 2014-08-30T22:00:12.873 回答
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")
于 2014-09-30T14:56:32.307 回答
1

I used this code to switch popup from popup it works fine.

function switchpop()
{
    $( '#popupMenu' ).popup( 'close' );  
    $( "#popupMenu" ).bind({popupafterclose: function(event, ui) 
            { 
                $( "#notes" ).popup( "open" );
            }
            });                
}
于 2014-08-15T20:26:20.237 回答
1

It seems that chaining popups is not possible.

The solution:

$( document ).on( "pageinit", function() {
    $( '.popupParent' ).on({
        popupafterclose: function() {
            setTimeout( function(){ $( '.popupChild' ).popup( 'open' ) }, 100 );
        }
    });
});
于 2013-08-25T14:25:10.887 回答
0

经过四个小时的斗争,我将问题简化为:

这是在第一个弹出窗口的按钮单击功能中

    $('#popupCall').popup('close');

    window.setTimeout(function () { $('#popupContact').popup('open') }, 50);
于 2014-09-24T13:45:01.313 回答