2012-11-04 61 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(){'就足够了。 –