2011-07-19 56 views
1

我有一個方法$ .mobile.changePage的問題,實際上這個方法,當我用phonegap轉換應用程序,不起作用。

這是我的頁面.html的代碼。有解決方案嗎?

頁的index.html

<!DOCTYPE html> 
<html> 
<head> 
    <title>Prova </title> 

    <link rel="stylesheet" href="css/jquery.mobile-1.0b1.css" /> 
    <script src="js/jquery-1.6.1.min.js"></script> 
    <script src="js/jquery.mobile-1.0b1.js"></script> 

    <script> 
    $(document).ready(function() { 

     $('#linkpersonale').click(function() { 
      $.mobile.changePage("#personale", null, true, true); 
     }); 

    }); 
    </script> 


</head> 
<body> 

<div data-role="page" id="home"> 

<header data-role="header"> 
    <h1>Prova Page1</h1> 
</header> 

<div data-role="content" id="content"> 


    <ul data-role="listview" data-inset="true" data-theme="c" data-dividertheme="b" data-counttheme="d"> 
     <li> 
      <a class="ui-link-inherit" id="linkpersonale"> 
       <h3 class="ui-li-heading">Personale</h3> 
       <p class="ui-li-desc">...</p> 
      </a> 
     </li> 
    </ul> 

</div> 


<footer data-role="footer" data-role="footer" data-id="footer-nav" data-position="fixed"> 
    <div data-role="navbar" id="navbar_home"> 
     <ul> 
      <li><a href="#home" data-icon="home" data-iconpos="top" data-theme="a">Home</a></li> 
     </ul> 
    </div> 
</footer> 

</div> 

</body> 
</html> 

頁personale.html

<!DOCTYPE html> 
<html> 
<head> 
    <title>Prova </title> 

</head> 
<body> 


<div data-role="page" id="personale"> 

<header data-role="header"> 
    <h1>Prova Pag2</h1> 
</header> 


<div data-role="content"> 

<ul data-role="listview" data-inset="true" data-theme="c" data-dividertheme="b" data-counttheme="d"> 
    <li> 
     <a class="ui-link-inherit" href="#"> 
      <h3 class="ui-li-heading">Etc etc</h3> 
      <p class="ui-li-desc">...</p> 
     </a> 
    </li> 

</ul> 

</div> 

<footer data-role="footer" data-role="footer" data-id="footer-nav" data-position="fixed"> 
    <div data-role="navbar"> 
     <ul> 
      <li><a href="#" data-icon="home" data-icon="home" data-iconpos="top" data-theme="a" data-transition="slide">Home</a></li> 
     </ul> 
    </div> 
</footer> 

</div> 

</body> 
</html> 

一些建議嗎? PS:對不起,我的英語,我是意大利;)

+0

你可以粘貼'changePage'函數嗎? – Rafay

+0

增加了jquery-mobile標籤,希望能夠帶來一些JQuery Mobile傢伙在這裏。 – Caimen

回答

1

嘗試

$.mobile.changePage("personale.html", null, true, true); 
4

PhoneGap的是這裏的紅鯡魚。您應該將其作爲普通的舊jQM代碼進行測試,您會發現它在那裏也不起作用。這是因爲您在不包含它的HTML文件中引用divindex.html)。

我會嘗試在personale.html上調用changePage()而不是#personale

從文檔上$.mobile.changePage()

的,以參數可以接受一個字符串(如文件URL或本地元素的ID)...

1

我覺得這是問題:

$.mobile.changePage("#personale", null, true, true); 

因爲personale.html是一個不同的文件,我認爲你需要添加一個.html。相反,嘗試

$.mobile.changePage("personale.html", null, true, true); 

如果你想使用前面的代碼,那麼你只需要在personale.html代碼添加到您的pageindex.html頁面。無論如何,正確的頁面將顯示出來,然後您可以像切換一樣通過IDS進行切換。

PageIndex.html:

<div data-role="page" id="home"> 
<!-- CODE --> 
</div> 
<div data-role="page" id="personale"> 
<!-- CODE --> 
</div> 

注:這將導致與黑莓和HTC手機,以及許多其他手機的錯誤。他們會同時看到兩頁。另一方面,任何mobile.changePage()呼叫將不會與他們一起工作

1

正如在其他答案中說,您可以將頁面更改爲'pagename.html'或它的ID。

您正在使用它的ID 'personale'

在這種情況下,你應該使用JQ標誌,以表明你正在使用一個變量(= $):

$("#personale") 

所以儘量

$.mobile.changePage($("#personale"), null, true, true); 

還有一件事,你知道在移動html頁面,你可以把更多的頁面元素放在1個文件中,對吧?

這可以在切換頁面時節省一些加載時間。

相關問題