我不是程序员,我主要是设计师,所以我在开发某些东西时遇到了一些困难。
我对在以下场景中如何使用深度链接和asual jquery(或其他更合适的插件)有疑问。
导航结构更像是:
<ul>
<li><a href="/pt/empresa/historia" title="História">História</a></li>
<li><a href="/pt/empresa/historia/missao" title="Missão">Missão</a></li>
<li><a href="/pt/empresa/historia/universo" title="Universo">Universo</a></li>
<li><a href="/pt/empresa/historia/numeros" title="números">números</a></li>
</ul>
和div
<div id="content-mask">
<div id="content-container">
</div>
</div>
我想将单击链接的页面中的内容容器的内容加载到内容容器中。
最佳答案
您可以使用load
方法:
Load data from the server and place the returned HTML into the matched element.
$(document).ready(function(){
$('ul li a').click(function(e){
e.preventDefault() // prevents the default action of the click event
$('.content-container').load(this.href) // loads the content based on the value of href attribute
// or $('.content-container').load(this.href + " .content-container") in case that I have misunderstood your question
})
})
请注意,您只能有一个 content-container
类的元素,否则您会出现重复的内容。
关于jquery - 使用常用的 jquery 和深度链接将内容加载到 div 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12158995/