2013-05-26 98 views
5

如果我加載一個頁面到「curr_recipe」,並希望返回頁腳中的鏈接到#home在頁面上沒有可用的點擊事件#home; jQuery代碼來自M-的index.php和我使用的用戶代理功能,因爲我想這個網頁在移動設備和PC的電腦/筆記本電腦等jQuery手機沒有點擊事件後.load()

$(document).ready(function() { 

     $("#btnSearch").click(function() {searchFiles()}); 
     $("#testrecipe").click(function() { 
      $.mobile.changePage("#actRecipe"); 
      $("#curr_recipe").load("htmltodisplay.html", function() { 
       $.mobile.changePage("#home", {transition: "fade"}); 
      }); 
     }); 
     $("#btnReset").click(function() {resetInput()}); 
     $("#txtRecipe").click(function() {resetInput()});   
     $("#toSearch").click(function() {$.mobile.changePage("#searchPage", {transition: "slide"})}); 
     $("#allrecipes").click(function() { 
      $.mobile.changePage("#recipePage", {transition: "slide"}); 
      readFiles(true); 
     }); 
}); 

<div data-role="page" id="home"> 
    <div data-role="header"> 
    <h1>Head</h1> 
     </div> 
     <div data-role="content"> 
      <h1>What to do?</h1> 
     </div> 
     <div class="nav"> 
      <ul style="font-size:24px;" data-role="listview"> 
       <button id="toSearch">Rezept suchen</button> 
       <button id="allrecipes">Alle Rezepte</button> 
       <button id="testrecipe">Test Rezept</button> 
      </ul> 
     </div> 
    </div> 

<div data-role="page" id="actRecipe"> 
    <div id="curr_recipe" data-role="content"> 

    </div> 
    <div data-role="footer" data-position="fixed" data-id="oneFooter"> 
     <a style="font-size: 24px; width: 100%; border-radius: 0px;" href="#home" data-transition="fade">Menü</a> 
    </div> 
</div> 

網頁加載

<!DOCTYPE html> 

<html lang="en" xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<script src="./jquery-2.0.0.js"></script> 
<link type="text/css" rel="stylesheet" media="screen" href="./css/recipe_screen.css" /> 
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" /> 
<title></title> 

<script> 
    $(document).ready(function() { 
     var UserAgent = navigator.userAgent.toLowerCase(); 

     if (UserAgent.search(/(iphone|ipod|opera mini|fennec|palm|blackberry|android|symbian|series60)/) > -1) { 
      // mobiles Endgerät 
      document.getElementById("back").style.display = "none"; 
     } else {} 

    }); 
</script> 
</head> 
<body> 
<div id="title"></div> 
<h2 class="rphone"></h2> 
<div class="content"> 
    <ul id="ingredients"> 

    </ul> 
</div> 
<h2 class="rphone"> </h2> 
<div class="content" id="cooking"> 

</div> 
<div id="back"> 
    <a id="linkback" href="/rezepteV1/index.php">Zum Menü</a> 
</div> 
</body> 
</html> 
+0

你需要給你的負載添加一個回調() 實際上只有當load()完成時才執行回調 – happy

+0

確保你的.html文件沒有錯誤加載。即標籤未關閉或單擊該文件內的事件。 – Omar

+1

.html文件中沒有錯誤,我添加了回調: $(「#testrecipe」)。click(function(){ $ .mobile.changePage(「#actRecipe」); $(「#curr_recipe 「).load(」anypage.html「,function(){ \t $ .mobile.changePage(」#home「,{transition:」fade「}); }); }); 但仍然存在相同的問題,我可以看到頁面#home,但我無法「交互」,直到我手動重新加載頁面 – tommygeek

回答

1

編輯:

你有沒有檢查jQuery的()? http://api.jquery.com/on/

假設事件不能被觸發,因爲該元素當時不存在。使用on()你可以等待它,所以無論如何它都可以在任何時候被解僱。

+0

對不起,但我不' t懂得如何/: – tommygeek

+0

你能提供更多的代碼嗎?也許問題不在你認爲的地方 – happy

+0

你還需要更多的代碼嗎? – tommygeek