当前位置: 首页 > 知识库问答 >
问题:

如何在jQuery移动多页面模板结构中显示第二页作为默认页面?

澹台建华
2023-03-14

如何将第二个页面显示为jQuery mobile多页面模板结构中的默认页面?

<body> 
<div data-role="page" id="foo">
    <div data-role="header">
        <h1>Foo</h1>
    </div>
    <div data-role="content">   
        <p>I'm first in the source order so I'm shown as the page.</p>      
    </div>
</div>
<div data-role="page" id="home">
    <div data-role="header">
        <h1>Home</h1>
    </div>
    <div data-role="content">   
        <p>I'm the second in the source order so I'm hidden when the page loads. I'm just shown if a link that references my id is beeing clicked.</p>      
    </div>
</div>
<div data-role="page" id="bar">
    <div data-role="header">
        <h1>Bar</h1>
    </div>
    <div data-role="content">   
        <p>I'm the second in the source order so I'm hidden when the page loads. I'm just shown if a link that references my id is beeing clicked.</p>      
    </div>
</div>
</body>

共有2个答案

宰父保臣
2023-03-14

我知道这个问题有点老,但我偶然发现了一个简单的解决方案:

window.location.href = "_dash.html#page-two";

或者,如果您从单独的页面导航,您可以制作一个链接,将u放在第二页中,如下所示:

<a href="_dash.html#page-two">link to second page</a>

只需在url末尾添加第二个页面的页面id

宗安翔
2023-03-14

工作示例:http://jsfiddle.net/Gajotres/UfDaf/

这部分将阻止正常的页面加载。不要忘记,就像在我的示例中一样,Mobeinit必须在初始化jQuery Mobile之前初始化。

$(document).on("mobileinit",function() {
    $.mobile.autoInitializePage = false;
}); 

这部分将开始手动页面初始化:

$(document).ready(function() {            
    window.location.hash = 'home';
    $.mobile.initializePage();
});

虽然我通常建议不要在这里使用文档就绪,但我们需要它来启动手动更改。

以防jsFiddle关闭。

HTML:

<!DOCTYPE html>
<html>
    <head>
        <title>jQM Complex Demo</title>
        <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
        <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; minimum-scale=1.0; user-scalable=no; target-densityDpi=device-dpi"/>
        <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-1.9.1.min.js"></script>
        <script>
            $(document).on("mobileinit",function() {
                $.mobile.autoInitializePage = false;
            });        
        </script>
        <script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>    
    </head>
    <body>
        <div data-role="page" id="foo">
            <div data-role="header">
                <h1>Foo</h1>
            </div>
            <div data-role="content">   
                <p>I'm first in the source order so I'm shown as the page.</p>      
            </div>
        </div>
        <div data-role="page" id="home">
            <div data-role="header">
                <h1>Home</h1>
            </div>
            <div data-role="content">   
                <p>I'm the second in the source order so I'm hidden when the page loads. I'm just shown if a link that references my id is beeing clicked.</p>      
            </div>
        </div>
        <div data-role="page" id="bar">
            <div data-role="header">
                <h1>Bar</h1>
            </div>
            <div data-role="content">   
                <p>I'm the second in the source order so I'm hidden when the page loads. I'm just shown if a link that references my id is beeing clicked.</p>      
            </div>
        </div>        
    </body>
</html>   

Javascript:

$(document).ready(function() {            
    window.location.hash = 'home';
    $.mobile.initializePage();
});
 类似资料:
  • 我有一个问题与WooCommerce/WordPress模板。我以前什么都有。 我的文件中有以下代码: 这段代码为产品类别选择了我的自定义归档模板,并在主页上购物。突然,它不再起作用了。似乎WordPress不能使用自定义文件从了。单个产品页面和产品类别出于某种原因使用。我通过在我的主题文件夹上创建文件single-product.php来修复单个产品页面的问题。这个工作正常,但是我不能对WooC

  • 我搜索了一下,所有可能对我有帮助的多页面引用都是多年前的和一个古老的jqm版本。 澄清一下:内部页面是一个托管在单独文件中但位于同一服务器上的页面,与我的索引位于同一目录中。html。外部页面将托管在不同服务器/域上的单独文件中。 我的目标是:我有一个应用程序,它作为一个单一的文档多页面,看起来很胖。它有大约20个页面(div-data-part=page)。我想把这些页面中的大部分放在内部页面中

  • 是否有一些配置可以为特定角色的网站页面提供默认权限? 与我们在控制面板中的功能类似→ 门户设置→ 用户,这里我们可以指定创建用户时可以为用户分配哪些角色、站点或用户组。 详细说明: 我创建了一个新角色,比如,Role 我知道这是可能的,通过一个侦听器钩子,拥有一个并重写各种方法,但我正在寻找另一个更简单或更干净的解决方案。 谢谢

  • 问题内容: 我在一页上有2个表格。其中一种形式具有始终显示的Recaptcha。另一个应仅在某些事件(例如,最大程度地尝试登录)后才显示recaptcha。所以有时候我需要2个Recaptchas才能出现在同一页面上。这可能吗?我知道我可能两者都可以使用一个,但是我有布局的方式,我更喜欢有2个。谢谢。 更新: 嗯,我想这可能是不可能的。有人可以推荐另一个捕获库与reCaptcha一起使用吗?我真的

  • 我正在使用jasperreport-4.5.0生成报告。它正在正确地生成报告。但是如果我的数据库中有大量数据,那么报告vl会显示在不同的页面中。所以我的要求是,如果我的报告有12页,那么我想显示12页中的第1页,12页中的第2页,12页中的第3页……就像我的页眉带一样。我怎么能做到这一点,任何人都可以对此提出一个想法。

  • 我使用博客portlet(Liferay 7.2 GA1)在一个页面示例中列出所有博客帖子。com/web/guest/blog,我使用显示模板页面查看博客详细信息。 问题是,当我打开一个帖子的URL更改为:http://localhost:8080/web/guest/b/blog-post-example 博客的友好网址从: http://localhost:8080/web/guest/bl