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

标签 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>

最佳答案

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

<!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>

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

关于jquery - 在 jQuery Mobile 中,为什么这个弹出窗口不关闭?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13154278/

相关文章:

PHP 访问被拒绝

jquery-mobile - 使用面板时 jQuery Mobile 1.3.2 错误

javascript - 如何根据 Accordion slider 中的内容调整嵌套 div 的高度?

javascript - jQuery NoUiSlider 不能使用最大值 10

javascript - html css Loader需要完成的位置

javascript - 在 WP7 上存储数据?

ajax - jquery mobile 取消 pagebeforeshow 事件

javascript - 如何使用 Angular 检测父 div 中的所有图像源并添加到对象?

javascript - 从右向左追加 div

复选框选中事件的javascript函数