Javascript 如何使用jquerymobile在几秒钟后隐藏div?

Javascript 如何使用jquerymobile在几秒钟后隐藏div?,javascript,jquery,jquery-mobile,Javascript,Jquery,Jquery Mobile,我想在加载网页时显示一个div 5秒钟,然后让它消失。这是我的代码: <html> <head> <script src="//code.jquery.com/jquery-1.11.1.min.js"></script> <script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> <script>

我想在加载网页时显示一个div 5秒钟,然后让它消失。这是我的代码:

<html>
<head>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>

<script>
setTimeout(function() {
    $('#mask').hide();
}, 5000);
</script>
</head>
<body>

<div id="mask">
<h2>This div will fade out </h2>
</div>

</body>
</html>
但是,如果我删除调用jQuery mobile javascript的单行代码,上面的代码就不起作用了

<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
它工作得很好。
关于如何让jQuery和jQuery mobile都在本节中工作,您有什么想法吗?

您需要使用jQuery mobile api。在$document.on'pageinit'事件回调中嵌入超时函数。另外,我不确定它是否被称为“pageinit”,但有一个Jquery移动事件的行为类似于$document.on“ready”。在jQuery初始化许多事件监听器时,对JQM api进行一些研究,如:

    jQuery(document).ready(function ($) {
    setTimeout(function () {
        $('#hide').hide();
    }, 5000);
});

尝试在第一页中包含div:

<div data-role="page" id="page1">
    <div data-role="header">
         <h1>My page</h1> 
    </div>
    <div role="main" class="ui-content">
        <div id="mask">           
            <h2>This div will fade out </h2>
        </div>
    </div>
</div>
工作


你能添加适合你的代码吗?发布不起作用的确切代码,而不仅仅是起作用的代码。JQuery Mobile不是问题所在:
$(document).on("pagecreate", "#page1", function () {
    setTimeout(function () {
        $('#mask').hide(800);
    }, 5000);
});