在jQuery Mobile中,为什么这个弹出窗口不关闭?

时间:2012-10-31 08:55:23

标签: jquery jquery-mobile

我按照http://jquerymobile.com/test/docs/pages/popup/index.html呼叫关闭,但没有发生任何事情(显然我希望在这种情况下根本不显示):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html> 
<head> 
    <title>popup</title> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
    <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
    <meta http-equiv="Content-Type" content="text/html; charset= ISO-8859-5">
    <script>
    $(document).ready(function () {
        $("#popupBasic").popup();
        $("#popupBasic").popup("open");
        $("#popupBasic").popup("close");
    });
    </script>
</head> 
<body> 

<div data-role="page">
    <div data-role="popup" id="popupBasic">
        <p>This is a completely basic popup, no options set.</p>
    </div>

</div>

</body>
</html>

2 个答案:

答案 0 :(得分:2)

将你的脚本放入正文并且它可以正常工作,我还添加了一个标题

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
    <title>popup</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
    <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
    <meta http-equiv="Content-Type" content="text/html; charset= ISO-8859-5">
</head>
<body>

  <div data-role="page" id="myPage">
    <div data-role="content">
      <h1>Popup</h1>
      <div data-role="popup" id="popupBasic">
        <p>This is a completely basic popup, no options set.</p>
      </div>
    </div>

    <script>
      $(document).bind('pageinit', function() {
        setTimeout(function(){
          $("#popupBasic").popup();
          $("#popupBasic").popup("open");
          $("#popupBasic").popup("close");
        }, 100);
      });
    </script>
  </div>

</body>
</html>

编辑:如here所述,使用$(document).bind('pageinit')代替$(document).ready(),现在添加了100毫秒的短暂延迟。现在可以在Firefox Nightly和Chrome中使用......

答案 1 :(得分:0)

我遇到了同样的问题。我的代码中有一个带有警报的导航事件,并且警告表示在chrome中弹出后调用了导航事件,并且因为jQM没有将带有弹出窗口的页面写入历史记录,所以您将返回第一个chrome欢迎页面。

我还没有解决这个问题,所以我使用了这个插件:

Dmitry Semenov的Magnific Popup v0.9.4

在我的jQM“pageshow”事件中,通过API直接打开Popup。 这是页面:http://kancelaria.danekilian2.pl/

相关问题