[英]Jquery loading content via ajax
I have an unordered list that will be used as a nav bar我有一个将用作导航栏的无序列表
<ul>
<li><a href="content/index.html" class="selected">Home</a></li>
<li><a href="content/about.html" class="nav_bubble">About</a></li>
<li><a href="content/projects.html" class="nav_bubble">Projects</a></li>
<li><a href="content/tutorials.html" class="nav_bubble">Tutorials</a></li>
</ul>
and I have some javascript to load the content into a div我有一些 javascript 将内容加载到 div
<script type="text/javascript">
$(function(){
$("div#navcontainer > ul > li > a").click(function(e){
e.preventDefault();
$.ajax({
url: e.currentTarget.href,
cache: false,
dataType: "html",
success: function(data) {
console.log(data);
$("#content").html(data);
}
});
});
});
</script>
All of that works, the question is, what happens when I load a page from my content folder that has a link in it?所有这些都有效,问题是,当我从包含链接的内容文件夹中加载页面时会发生什么? It sends your browser to the page instead of loading it into the div.它将您的浏览器发送到页面而不是将其加载到 div 中。 How can I recursivly load all links into the content div instead of sending the user directly to them?如何将所有链接递归加载到内容 div 中,而不是将用户直接发送给它们?
Change:改变:
$("div#navcontainer > ul > li > a").click(function(e){
To:至:
$("div#navcontainer > ul > li > a, div#content a").live('click',function(e){
"Attach a handler to the event for all elements which match the current selector, now and in the future." “将处理程序附加到与当前选择器匹配的所有元素的事件,现在和将来。”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.