【问题标题】:jQuery mobile dialog close automatically in chromejQuery 移动对话框在 chrome 中自动关闭
【发布时间】:2013-08-26 03:18:49
【问题描述】:

我目前正在开发一个 jQuery 移动页面。 我需要在对话框中显示一条错误消息,该消息在 FF 和 IE 中完美运行。 但是当我在 chrome 中打开页面时,对话框会自动关闭。

这是我的代码:

<!DOCTYPE html>
<html>
<head>
    <title>Header</title>
    <meta name="viewport" id="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />

    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css" />
    <script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>  

    <script type="text/javascript">
        $(document).ready(function () {
            $.mobile.changePage('#errorDialog', { transition: 'pop', role: 'dialog' });
        }); 
    </script>
</head>
<body>
    <div data-role="page" data-theme="a">
        <div data-role="header" data-position="fixed">
            <h1>Home</h1>
        </div>
        <div data-role="footer" data-position="fixed">
            <h4>Footer</h4>
        </div>
    </div>

    <div id="errorDialog" data-role="dialog" data-close-btn="right" data-theme="a">
        <div data-role="header">
            <h1>Error</h1>
        </div>

        <div data-role="content">
            <p>Error Message...</p>
        </div>
    </div>
</body>
</html>

我做错了吗?

【问题讨论】:

    标签: javascript jquery html mobile dialog


    【解决方案1】:

    这可能是您使用的 jquerymobile 版本的问题。试试下面的代码:

    <link rel=stylesheet href=http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css />
    <script src=http://code.jquery.com/jquery-1.6.min.js></script>
    <script src=http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js>
    </script>
    
    <script type="text/javascript">
    $(document).ready(function () {
       setTimeout(function () {
        $.mobile.changePage('#errorDialog', { transition: 'pop', role: 'dialog' });
    }, 100);
    }); 
    </script>
    </head>
     <body>
    <div data-role="page" data-theme="a">
        <div data-role="header" data-position="fixed">
            <h1>Home</h1>
        </div>
        <div data-role="footer" data-position="fixed">
            <h4>Footer</h4>
        </div>
    </div>
    
    <div id="errorDialog" data-role="dialog" data-close-btn="right" data-theme="a">
        <div data-role="header">
            <h1>Error</h1>
        </div>
    
        <div data-role="content">
            <p>Error Message...</p>
        </div>
      </div>
    </body>
     </html>
    

    【讨论】:

    • 谢谢,对话框不再自动关闭。但是我对这个解决方案还有另一个问题,在用户关闭对话框后,chrome(只有 chrome)会导航到一个空白页面。
    • 最好你可以为此设置一个超时。我已经编辑了答案,请检查它..
    • 非常感谢,你拯救了我的一天
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-28
    • 1970-01-01
    相关资源
    最近更新 更多