1

使用 jQuery Mobile,我无法弹出加载了谷歌地图的弹出窗口。如果我触摸 id="popupBasic" 什么都不会弹出。很奇怪,但是如果没有加载谷歌地图 api,弹出窗口就可以了!

>

 <html>

<head>

    <meta name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1">

    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
    <title>Beer Me</title>
    <link rel="stylesheet" href="css/jquery.mobile-1.3.1.css" />
    <link rel="stylesheet" href="css/jquery.mobile.structure-1.3.1.css" />
    <link rel="stylesheet" href="css/datepicker.css" />
    <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
    <script type="text/javascript" src="js/jquery.js"></script>
    <script type="text/javascript" src="js/jquery.mobile-1.3.1.js"></script>
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
    <script type="text/javascript" charset="utf-8" src="js/map.js"></script>
    <script type="text/javascript" charset="utf-8" src="markers.js"></script>
    <script>

        $.mobile.page.prototype.options.domCache = true ;
        $.mobile.allowCrossDomainPages = true;
        $(document).on('pageshow', '#map', function (event)
        {
            max_height();
            $(document).on('click', '#myposition', function (event){
                navigator.geolocation.getCurrentPosition(onSuccess, onError,{'enableHighAccuracy':true,'timeout':20000});
            });
        });

    </script>
    <script type="text/javascript" charset="utf-8" src="js/datepicker.js"></script>
    <script type="text/javascript" charset="utf-8" src="js/datepicker.mobile.js"></script>
</head>
<body onload="onLoad()">
<div data-role="page" id="map">
   <div data-role="header" data-theme="b">
        <a href="index.html" data-icon="grid" rel="external">Menu</a>
        <h1>Map Header</h1></div>
    <div data-role="content" style="width:100%; height:100%; padding:0;">
        <div data-role="popup" id="popupBasic">
            <p>This is a completely basic popup, no options set.<p>
        </div>
        <div id="map_canvas" style="width:100%;height:100%"></div>
    </div>
    <div data-role="footer" data-theme="b" data-position="fixed">
        <div data-role="navbar">
            <ul>
                <li><a href="#leftpanel" data-role="button" data-inline="true"   data-icon="grid" >Date</a></li>
                <li><a href="#" data-icon="star" id="testbtn">Favs</a></li>
                <li><a href="#" data-icon="gear" id="myposition">My position</a></li>
                <li><a href="#popupBasic" data-rel="popup">Open Popup</a></li>
            </ul>
        </div><!-- /navbar -->
    </div>
</div>
</body>
</html>

有人有同样的问题吗?我想不通。。

问候,

坦率

4

1 回答 1

1

工作示例:http: //jsfiddle.net/Gajotres/GHZc8/

我已经更改了您的示例,如果您单击按钮#myposition,将显示弹出窗口。

HTML:

<!DOCTYPE html>
<html>
    <head>
        <title>jQM Complex Demo</title>
        <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
        <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; minimum-scale=1.0; user-scalable=no; target-densityDpi=device-dpi"/>
        <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>          
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css" />
        <script>
            $(document).bind("mobileinit", function(){
                $.mobile.page.prototype.options.domCache = true ;
                $.mobile.allowCrossDomainPages = true;
            });
        </script>        
        <script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>           
    </head>
    <body>
        <div data-role="page" id="map">
            <div data-role="header" data-theme="b">
                <a href="index.html" data-icon="grid" rel="external">Menu</a>
                <h1>Map Header</h1>
            </div>
            <div data-role="content" style="width:100%; height:100%; padding:0;">
                <div data-role="popup" id="popupBasic">
                    <p> This is popup</p>
                </div>
                <div id="map_canvas" style="width:100%;height:100%"></div>                 
            </div>
            <div data-role="footer" data-theme="b" data-position="fixed">
                <div data-role="navbar">
                    <ul>
                        <li>
                            <a href="#leftpanel" data-role="button" data-inline="true"   data-icon="grid" >Date</a>
                        </li>
                        <li>
                            <a href="#" data-icon="star" id="testbtn">Favs</a>
                        </li>
                        <li>
                            <a href="#" data-icon="gear" id="myposition">My position</a>
                        </li>
                        <li>
                            <a href="#popupBasic" data-rel="popup" id="openPopup">Open Popup</a>
                        </li>
                    </ul>
                </div>
                <!-- /navbar -->
            </div>
        </div>     
    </body>
</html>     

CSS:

#popupBasic {
    width: 300px !important;
    height: 300px !important;    
}

Javascript:

$(document).on('pageshow', '#map', function (event) {
    max_height();
    $(document).on('click', '#myposition', function (event){
        navigator.geolocation.getCurrentPosition(onSuccess, onError,{'enableHighAccuracy':true,'timeout':20000});
    });
});

function max_height() {
    var header = $.mobile.activePage.find("div[data-role='header']:visible");
    var footer = $.mobile.activePage.find("div[data-role='footer']:visible");
    var content = $.mobile.activePage.find("div[data-role='content']:visible:visible");
    var viewport_height = $(window).height();

    var content_height = viewport_height - header.outerHeight() - footer.outerHeight();
    if((content.outerHeight() - header.outerHeight() - footer.outerHeight()) <= viewport_height) {
        content_height -= (content.outerHeight() - content.height());
    } 
    $.mobile.activePage.find('[data-role="content"]').height(content_height);
}


function onSuccess(position) {       
    var minZoomLevel = 15;

    var map = new google.maps.Map(document.getElementById('map_canvas'), {
        zoom: minZoomLevel,
        center: new google.maps.LatLng(position.coords.latitude, position.coords.longitude),
        mapTypeId: google.maps.MapTypeId.ROADMAP
    });    
}

function onError() {
    alert('Error');
}
于 2013-05-15T14:37:19.423 回答