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

除非刷新,否则链接无法工作

魏健柏
2023-03-14

我目前正在使用JQuery mobile开发一个移动网站。我在我的foobar中使用了多个页面。html导航,如下所示:

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link rel="stylesheet" href="style/jquery.mobile-1.3.1.css" />
    <script src="jquery-js/jquery-1.10.1.js"></script>
    <script src="jquery-js/jquery.mobile-1.3.1.js"></script>
    <title>Foobar</title>
</head>

<body>
    <div data-role="page" id="foo">
        <div data-role="content">
            <a href="#bar" data-role="button">Go to Bar</a>
        </div>
    </div>

    <div data-role="page" id="bar">
        <div data-role="content">
            <p>Bar</p>
        </div>
    </div>
</body>

我加载foobar。html文件,单击Go to Bar,即可正常工作;然而,当我从索引导航时。hmtl到foobar。html并再次测试,链接无法工作。刷新页面可以解决此问题。

如何解释这种行为以及如何修复它?

共有1个答案

洪光霁
2023-03-14

在使用jQuery Mobile和多个HTML文件时,从索引开始时必须了解这一点。html到foobar。html将仅加载*第一页。基本上,jQuery Mobile将剥离页面的其余部分,包括标题和正文的其余部分。

因此,当处理多个HTML页面时,只有第一个页面可以有多个内部页面,所有其他HTML页面只能有一个页面。在您的情况下,只有page\foo加载到DOM中,page\bar被丢弃。

另外,我还有一篇文章描述了jQuery Mobile如何处理多个HTML页面加载。

<!DOCTYPE html>
    <html lang="en">
        <head>
            <!-- META TAGS Declaration -->
            <meta charset="UTF-8">
            <title>TEst</title>
            <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0;" />
            <meta name="apple-mobile-web-app-capable" content="yes" />
            <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 src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>  
            <script>
            $(document).on('pagebeforeshow', '#foo', function(){ 
                alert($('#body-test').html());
            });
            </script>           
        </head>

        <body id="body-test">
            <div data-role="page" id="portfolio"  data-add-back-btn="true">             
                <div data-role="content" data-theme='c' >
                    <a href="test.html" data-role="button">Go to Bar</a>
                </div>
            </div><!-- Page Project #1 -->
        </body>     
</html>
<html>
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1"> 
        <link rel="stylesheet" href="style/jquery.mobile-1.3.1.css" />
        <script src="jquery-js/jquery-1.10.1.js"></script>
        <script src="jquery-js/jquery.mobile-1.3.1.js"></script>
        <title>Foobar</title>
    </head>

    <body>
        <div data-role="page" id="foo">
            <div data-role="content">
                <a href="#bar" data-role="button">Go to Bar</a>
            </div>
        </div>

        <div data-role="page" id="bar">
            <div data-role="content">
                <p>Bar</p>
            </div>
        </div>
    </body>
</html>

如果您运行此示例,它会告诉您(提醒您)仅加载了page#foo。

 类似资料:
  • 问题内容: 我正在用Java编写命令行程序的终端包装,然后使用ProcessBuilder生成子进程。将击键发送到子,我只是写从GUI直奔 给出。为了从子流程接收输出,我基本上有一个while循环,它从子流程的中读取: 这工作, 只有 当我立刻冲在输出 都 结束。也就是说,我必须刷新每个用户输入,并且子进程必须刷新自己的输入才能发生操作。否则,将等待从未真正发送的等待数据的块(子进程的stdout

  • 我有一个Jfreechart,它正在绘制一些模拟实时数据。当我将域轴设置为自动时,可以看到数据每秒更新一次。然而,我希望在更大范围内(比如说一整天)绘制数据。当我更改范围时,除非放大,否则无法看到绘图。 如何使其连续(显示序列中的每个观测点),以及如何在手动设置范围时使其可见

  • 我有一个jQuery移动页面,里面有JavaScript。问题是,除非刷新页面,否则JavaScript无法工作。这是我的代码:

  • 问题内容: 这是我的配置: 根据此处找到的logback文档(http://logback.qos.ch/manual/appenders.html#TimeBasedRollingPolicy),文件将根据我的fileNamePattern 每分钟翻转一次。 我观察了它是如何工作的,这是我的发现: 它不会在很短的时间内创建日志文件。 当新日志到达时,它只会为前一分钟创建一个日志文件。(例如,我在

  • 我的应用程序使用Spring 4.3. x、EhCache 3.6和javax Cache 1.1.0。以下是我在应用程序中配置javax CacheManager的方式: AppCacheManagerFactoryBean(只是JCacheManagerFactoryBean的自定义版本)帮助我为我的应用程序配置全局持久性目录。这是它的外观: 这是我如何定义缓存的。我使用Ehcache API