2012-11-04 62 views
0

如何隱藏jquery mobile包含的頁面。我想擁有該網站的移動版本和桌面版本,但移動版本會自動加載。我該如何改變這一點?如何隱藏默認的jQmobile頁面

代碼在這裏:

<!DOCTYPE html> 
<html> 
    <head> 
     <!-- For Mobile Devices --> 
     <meta name="viewport" content="width=device-width, initial-scale=1"> 
     <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css"> 
     <script src="http://code.jquery.com/jquery-1.10.2.min.js"></script> 
     <script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script> 

     <link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet" /> 
     <link href="../global/global.css" rel="stylesheet" /> 
     <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> 
     <script language="javascript" type="text/javascript" src="../bootstrap/js/bootstrap.min.js"></script> 
    </head> 
    <body> 
     <div > 
     <!-- The View Page (Summary) --> 
     <div data-role="page" id="summary"> 
      <div data-role="header"> 
      </div> 
      <div data-role="main" class="ui-content"> 
       <div class="jumbotron container"> 
        <center> 
         <img src="removeLogo.jpg" /> 
        </center> 
        <h2 class="txt-center"><u>Controls</u></h2> 
        <a class="btn btn-default">View</a> 
       </div> 
      </div> 
      <div data-role="footer"> 
      </div> 
     </div> 

     <div data-role="page" id="summary"> 
      <div data-role="header"> 
      </div> 
      <div data-role="main" class="ui-content"> 
       <div class="jumbotron container"> 
        <center> 
         <img src="removeLogo.jpg" /> 
        </center> 
        <h2 class="txt-center"><u>Controls</u></h2> 
        <a class="btn btn-default">View</a> 
       </div> 
      </div> 
      <div data-role="footer"> 
      </div> 
     </div> 
    </bod 

Y>

+0

你是什麼意思它沒有讓你發佈的代碼?你有錯誤嗎? – Lix

+0

啊..是的..這隻適用於那些對網站不熟悉的人......你可以把鏈接放在這樣的反引號之間。 – Lix

回答

6

DOM是沒有準備好你的腳本運行的時間。把它放在一個DOM ready event handler

$(function() { 
    // Interact with the DOM in here 
}); 

// Or, the slightly longer version 
$(document).ready(function() { 
    // Interact with the DOM in here 
}); 

或者,將你的JavaScript到身體的一端(之前收盤</body>標籤是共同的地方,但你需要參考將工作中的元素之後的任意位置) 。通過這樣做,在解析腳本時,瀏覽器已經解析了前面的標記,並且有一個幾乎完整的DOM樹供您訪問。

+2

11次出現這是問題:P – Lix

0

好的。我認爲原因是,你正試圖達到#左側佔位符,但它尚未加載。

<!DOCTYPE html> 
<html> 
    <head> 
     <title></title> 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
     <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script> 
     <LINK href="../styles.css" rel="stylesheet" type="text/css"> 
    </head> 
    <body> 
      <div id="leftcol"> 
       <a href="practice.html"><div class ="left-column-item">Practice!</div></a> 
       <a href="aboutUs.html"><div class ="left-column-item">About Us!</div></a> 
       <a href="contactUs.html"><div class ="left-column-item">Contact Us!</div></a> 
      </div> 
     <div id="left-placeholder">abc</div> 
     <div id ="left-pusher"></div> 
     <div id ="content">Math Practice Site <br> hello</div> 
    </body> 
    <script type ="text/javascript"> 
     alert($('#left-placeholder').html()); 
    </script> 
</html> 

把你的腳本放在它下面,它應該沒問題。或頁面加載像這樣的後啓動腳本:

$(document).ready(function(){ 
    alert($('#left-placeholder').html()); 
}); 

來源: http://api.jquery.com/ready/

+0

爲了避免這個問題,我幾乎總是在整個文件中添加腳本,如下所示: and inside $(document )。準備(); :) – Simon

+0

感謝您的回覆。這幫了很多。 –

+0

'$(document).ready(function(){'是不必要的。'$(function(){'就足夠了。 –