简体   繁体   English

通过将其他内容保持为静态来动态加载页面/内容

[英]Dynamic page/content loading by keeping other content as static

i want to load html page dynamically in my div element by keeping home.html page as default and on loading another html page the content other than div element should be static. 我想通过将home.html页面保留为默认值来在我的div元素中动态加载html页面,并且在加载另一个html页面时,除div元素之外的内容应该是静态的。 How can i achieve it? 我该如何实现? please help. 请帮忙。 I am using following codes... 我正在使用以下代码...

html code HTML代码

<nav class="main">
    <a href="home.html">Page 1</a>
    <a href="contact.html">Page 2</a>
    <a href="about.html">Page 3</a>
    <a href="product.html">Page 4</a>
    <a href="page5.html">Page 5</a>
</nav>

<div id="dynamic">
</div>

and my jquery code is 我的jQuery代码是

$(document).ready(function(){
    $('a').click(function(){
        $('#dynamic').load('home.html');
        return false;
    });
})

To load the page specified in the href of the anchor: 加载锚的href中指定的页面:

$('a').click(function(){
    $('#dynamic').load(this.getAttribute('href'));
    return false;
}

Try this approach. 试试这种方法。 The loading target url should be based on the link that has been clicked. 加载目标网址应基于已单击的链接。

$(document).ready(function(){
    $('nav a').click(function(event){
        event.preventDefault();

        $('#dynamic').load($(this).attr('href'));

        return false;
    });
})

Please see sample jsfiddle . 请参阅示例jsfiddle

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

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