jQuery移动对话框在chrome中自动关闭

jQuery mobile dialog close automatically in chrome

本文关键字:chrome 移动 对话框 jQuery      更新时间:2023-09-26

我目前正在开发一个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>

我做错什么了吗?

这可能是您使用的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>