2012-10-31 17 views
1

我打電話接近每http://jquerymobile.com/test/docs/pages/popup/index.html,但什麼也沒發生(很明顯,我希望它不會在這種情況下顯示在所有):在jQuery Mobile中,爲什麼不彈出關閉?

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

把你的腳本到身體和它的作品,我添加了另外一個頭

<!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現在加入100ms的短暫延遲。現在在Firefox Nightly和Chrome中運行...

+0

這會在Chrome中產生奇怪的行爲 - 當彈出窗口關閉時,它也會進入空白頁面。在Safari中,它似乎根本不起作用。 – fakeguybrushthreepwood

+0

讓它現在工作,看到更新... – Taifun

+0

對不起,延遲,仍然觀察在這個奇怪的行爲。當彈出窗口關閉時,它會進入空白頁面。 – fakeguybrushthreepwood

0

我遇到了同樣的問題。我的代碼中有一個帶警報的導航事件,並且警報顯示導航事件在Chrome中彈出後被調用,並且由於jQM沒有將彈出窗口寫入歷史中,因此您將返回到第一個歡迎頁面。

我還沒有解決這個問題,所以我已經使用這個插件:

通過Magnific酒店梅德謝苗諾夫

彈出彈出v0.9.4在我JQM「pageshow」事件通過API直接打開。 這是頁面:http://kancelaria.danekilian2.pl/

+0

您可以通過指定用於解決問題的插件來改進此答案。 – lmjohns3