弹出的jQuery移动打开弹出窗口

时间:2013-08-25 13:49:38

标签: jquery-mobile cordova popup

我在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 个答案:

答案 0 :(得分:10)

我的解决方案

$.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");
};

答案 1 :(得分:3)

我使用这个简单的函数进行解决:

function myPopup(myPage) {
    history.back();
    setTimeout(function () {
        $(myPage).popup('open');
    }, 100);
}

答案 2 :(得分: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")

答案 3 :(得分:1)

链接弹出窗口似乎不是possible

解决方案:

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

答案 4 :(得分:1)

我使用此代码从弹出窗口切换弹出窗口,它工作正常。

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

答案 5 :(得分:0)

经过四个小时的战斗后,我把问题解决了:

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

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

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