2013-04-25 80 views
0

這裏是HTML代碼:

<div data-role="page" id="mainMenu"> 
    <div data-role="header"> 

    </div> 
    <div data-role="content"> 
    <ul data-role="listview" data-inset="true" 
             style="margin-top:50%; margin-left:20%;"> 
    <li id="prayerId" data-theme="b"><a href="#"><img 
               src="css/images/namazimage.jpg" />PRAYERS </a> 
             </li> 
    <li id="goalId" data-theme="e"><a href="#"><img 
               src="css/images/namazimage.jpg" />GOAL </a> 
             </li> 

    </ul> 
    </div> 
    </div> 
    <!-- //////////////////////// PRAYER PAGE START ////////////////////////////////////// --> 
     <div data-role="page" id="prayer"> 
      <div data-role="header" data-theme="b"></div> 
      <div data-role="content"></div> 
      <div data-role="footer" data-theme="e" data-position="fixed"> 

       <div data-role="navbar"> 

        <ul> 
         <li id="namazId"><a href="#" data-role="tab" data-icon="grid">NAMAZ</a></li> 
         <li id="fastId"><a href="#" data-role="tab" data-icon="grid">FAST</a></li> 
        </ul> 
       </div> 
      </div> 

     </div> 

<!-- //////////////////////// PRAYER PAGE END ////////////////////////////////////// --> 

這個S這是寫在單獨的js文件的代碼:

$('#mainMenu').live('pageinit', function() { 
    $('#prayerId').off('click').on('click', function() { 
     alert("prayer id"); 
     $.mobile.changePage("#prayer", null, true, true); 
     //$.mobile.changePage('#loginPage', null, true, true); 

    }); 
}); 
$('#prayer').live('pageinit',function() 
{ 
    alert("prayer page"); 
    $('#namazId').off('click').on('click', function() { 
     alert("namaz page"); 
     //$.mobile.changePage('#mainMenu', null, true, true); 
     $.mobile.changePage('#namazPage', null, true, true); 

    }); 
}); 

但在這裏變化頁不能正常工作的jQuery的所有引用和已添加科爾多瓦使用cordova 2.0.0和jquery 1.7.1

+0

嘗試'$ .mobile.changePage( '#namazPage')'不爲空,真正的,真實的。 – Omar 2013-04-25 12:19:58

+0

@omar仍然沒有任何更改 – nida 2013-04-25 12:33:21

+0

@ user1668447檢查您的標籤。通常'changePage'在沒有關閉標籤或額外標籤時無法工作。 – 2013-04-25 12:57:06

回答

0

pageinit事件中刪除click事件。 pageinit僅在頁面初始化時觸發一次,之後,任何附加到它的事件都將被忽略。

$('#prayerId').off('click').on('click', function() { 
alert("prayer id"); 
$.mobile.changePage("#prayer", null, true, true); 
}); 

$('#namazId').off('click').on('click', function() { 
alert("namaz page"); 
$.mobile.changePage('#namazPage', null, true, true); 
}); 

Demo

+0

的問題,但我不想寫這個代碼在我的腳本標記,因爲這麼多人aer在一個項目多數民衆贊成爲什麼要避免衝突想要把我的代碼放在我的單獨的js文件中,名爲namaz.js我怎麼能寫我的代碼,請解釋 – nida 2013-04-25 13:59:27

+0

你可以這樣做'$(document).on('click','#prayerId',function )'或'$('a')。on('click','#prayerId',function()'或'$(document).on('click','a#prayerId',function()'。它可以用多種方式編寫,也可以用'#pageID'替換'document'。記住每個元素都應該有一個唯一的'id',不能被使用兩次。@ user1668447 – Omar 2013-04-25 14:03:12

+0

你有jqplot與從sqlite數據庫獲取數據? – nida 2013-04-25 14:06:19