链接到外部页面并自动将其 HTML 附加到原始页面的包装器中


Linking to external page and append its HTML within the original page's wrapper automatically

<?php include('header.php'); ?>
<div data-role="page" data-theme="a" id="site-wrapper">
    //Here I want to keep appending the information without having to include
    //header and footer files in every external page
</div>
<?php include('footer.php'); ?>

这是您进入网站时首次降落的地方:

<div data-role="main">
    <div class="center-wrapper" id="landing-container">
        <h2>Välkommen</h2>
        <p><b>Befintlig användare?</b></p>
        <a href="login.php" class="ui-btn ui-btn-inline ui-corner-all ui-shadow">Logga in</a>
        <p><b>Ny användare?</b></p>
        <a href="../includes/pages/register.php" class="ui-btn ui-btn-inline ui-corner-all ui-shadow">Registrera dig</a>
    </div>
</div>

现在,如果我单击"注册挖掘"(注册),我想获取文件的内容并将其附加到上面的#site-wrapper div。当它现在工作时,它会抓取内容并加载一个新页面,而不包含页眉和页脚文件,因为我没有将它们包含在文件中。根据我的理解,我认为 Jquery Mobile 会自动执行此操作,但事实并非如此,我是否必须使用 Jquery 手动进行 ajax 调用,然后将内容附加到div 中,或者有没有办法使用已经内置的 Jquery Mobile 函数自动执行此操作?无法从我的搜索中找到答案,所以希望我能在这里得到一个。

你需要 AJAX 来实现这一点。

$( "#site-wrapper" ).load( "folder/page.html", function() {
 // Callback function
});

这个剪断可以解决你的问题。将网址替换为您的文件!