简体   繁体   English

如何在jQueryMobile中使用来自不同html文件的相同面板

[英]How to use same panel from different html files in jQueryMobile

Is it possible to use a panel defined, in index.html in another page, eg, resutls.html ? 是否可以使用在另一个页面的index.html中定义的面板,例如resutls.html? Or do I need to define the panel in every page, and add the same html code in both pages ? 还是我需要在每个页面中定义面板,并在两个页面中添加相同的html代码?

Since I want my panel to be same in all pages. 因为我希望我的面板在所有页面中都相同。

This is my panel in index.html 这是我在index.html中的面板

<div data-role="page" id="home">
    <div data-role="panel" id="mypanel">
        <!-- panel content goes here -->
    </div>
    <!-- /panel -->
    <div data-role="header">
        <!-- beginning of header -->
        <div data-role="navbar" data-id="navbar">
            <!-- beginning of presistant navbar, this navbar will be shown in all
            pages -->
            <ul>
                <li> <a href="index.html" data-icon="search" class="ui-btn-active ui-state-persist">Search</a>

                </li>
                <li> <a href="#mypanel" data-icon="bars">More</a>

                </li>
            </ul>
        </div>
        <!-- /navbar -->
    </div>
    <!-- /header -->
    <div data-role="content" id="content">
        <!-- content -->
    </div>
    <!-- /content -->

If the two pages are on the same domain name you could simply load that element into your new page using JQuery. 如果两个页面使用相同的域名,则可以使用JQuery将该元素简单地加载到新页面中。

However this is not very SEO friendly as your links are being dynamically loaded into the page. 但是,由于您的链接正在动态加载到页面中,因此这不是非常适合SEO。

You will need to include the JQuery library then make the div on your new page, lets say: 您将需要包括JQuery库,然后在新页面上创建div,让我们说:

<div class="new-sidebar"></div>

Then load its contents with JQuery $('.new-sidebar').load('index.html #mypanel'); 然后使用JQuery $('.new-sidebar').load('index.html #mypanel');加载其内容$('.new-sidebar').load('index.html #mypanel');

Edit from comment: 编辑评论:

$( "#navbar ul li" ).click(function() {
  $('.new-sidebar').load('index.html #mypanel');
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM