如何在jquery移动对话框显示时自定义?

时间:2016-09-27 13:26:18

标签: javascript jquery html jquery-mobile

我需要能够选择何时打开jquery对话框,但我似乎没有任何工作。

到目前为止,我已尝试过这个

<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>

    <!-- Include meta tag to ensure proper rendering and touch zooming -->
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Include jQuery Mobile stylesheets -->
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">

    <!-- Include the jQuery library -->
    <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>

    <!-- Include the jQuery Mobile library -->
    <script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>

</head>
<body>
        <div data-role="main" class="ui-content">

            <a href="#myPopupDialog" data-rel="popup" data-role="dialog" data-position-to="window" data-transition="fade" class="ui-btn ui-corner-all ui-shadow ui-btn-inline">Open Dialog Popup</a>

            <a href="#" onclick="test()">Test</a>

            <div data-role="popup" id="myPopupDialog">

                <div data-role="header">
                    <h1>But wait theres more!</h1>
                </div>

                <div data-role="main" class="ui-content">
                    <h2 style="text-align: center;">Would you like an exclusive offer?</h2>
                    <a href="#" class="ui-btn ui-corner-all" data-rel="back">Sounds Good!</a>
                    <a href="#" class="ui-btn ui-corner-all ui-icon-back" data-rel="back" data-theme="a">No Thanks, Take me back..</a>
                </div>

                <div data-role="footer">
                    <h1>Footer Text</h1>
                </div>

            </div>
        </div>

<script>

    $(document).ready(function(){

        console.log(document.body.scrollTop);

        if(document.body.scrollTop === 0)
        {
            $.mobile.changePage('#myPopupDialog', 'pop', true, true);
        }

    });

</script>
</body>
</html>

哪个有效,但是当我在javascript中更改if语句时,如果我删除顶部的锚标记它也会显示... jQuery mobile让我感到困惑。

所以无论如何我的问题是如何手动在页面上显示一个对话框,我希望它显示在同一页面而不是另一页面。

1 个答案:

答案 0 :(得分:-1)

使用它:

$("#myPopupDialog").addClass("ui-page-active ui-page ui-page-theme-a")
相关问题