如何在默认情况下隐藏jQmobile页面

时间:2012-11-04 20:54:16

标签: javascript jquery html jquery-mobile

如何隐藏jquery mobile包含的页面。我想拥有该网站的移动版本和桌面版本,但移动版本会自动加载。我该如何改变?

代码在这里:

<!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'GT;

2 个答案:

答案 0 :(得分: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树可供您访问。

答案 1 :(得分:0)

好的。我想原因是,你正试图达到#left-placeholder但它尚未加载。

    <!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/

相关问题