jquery - 使用常用的 jquery 和深度链接将内容加载到 div 中

标签 jquery html

我不是程序员,我主要是设计师,所以我在开发某些东西时遇到了一些困难。

我对在以下场景中如何使用深度链接和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/

相关文章:

javascript - 如何从TextArea中获取数据并将其保存在Winword和记事本中?

html - 将元素放置在彼此之上

html - 复杂的 clearfix 有 2 个 float right 元素,我只想清除一个

html - 如何设置div表中列的宽度?

javascript - 使用 setInterval() 每 30 秒更新一次时间戳

javascript - 是否可以在特定条件下注册点击事件?

html - CSS - 无限动画(向右加载渐变移动)闪烁

jquery - 在 jquery 动画中添加淡入淡出切换效果

jquery - (为什么)jQuery 会让我的 slider 看起来很胖?

javascript - 表格: "Select all" button with multiple-choice checkboxes