jQuery Mobile Pages之外的持久性HTML [英] Persistent HTML outside of jQuery Mobile Pages

查看:80
本文介绍了jQuery Mobile Pages之外的持久性HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在主页上的< div data-role =page> 元素之外添加一些HTML。当通过ajax加载新页面时,不应该替换此HTML。

I want to include a bit of HTML outside of the <div data-role="page"> element on my main page. This HTML shouldn't be replaced when a new page is loaded in via ajax.

这个示例应用程序是在右上角有一个小的绝对定位的div仅在与AJAX调用相关的错误或应用程序的状态更新时显示。

The example application for this is to have a small absolutely positioned div in the top-right that is only displayed upon errors related to AJAX calls, or status updates with the application.

如果我尝试在index.html页面的主体中包含任何HTML,它立即被jQuery Mobile取代。我不想在我写的每一页上都包含这个div。

If I try and include any HTML in the body of my index.html page, it gets replaced by jQuery Mobile immediately. I don't want to have to include this div on each and every page I write.

任何想法?

推荐答案

我不认为 div 被替换。例如,这会将第一个看不见的 div 带到顶部:

I don't think divs get replaced. For example, this will bring the first unseen div to the top:

http://jsfiddle.net/RQkrj/2/

<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>
<style>
.top {
    z-index: 999;
}
</style>
<script>
$('div#page').live('pageshow', function(event, ui) {
    $('div#doesNotGetRemoved').addClass("top");
});
</script>
</head>
<body>

<div id="doesNotGetRemoved" style="background: red; position: absolute;">This is a div</div>

<div id="page" data-role="page">

    <div data-role="header">
        <h1>My Title</h1>
    </div><!-- /header -->

    <div data-role="content">    
        <p>Hello world</p>        
    </div><!-- /content -->

</div><!-- /page -->

</body>
</html>

这篇关于jQuery Mobile Pages之外的持久性HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆