开发者

Jquery loading content via ajax

I have an unordered list that will be used as 开发者_如何学JAVAa 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

<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. How can I recursivly load all links into the content div instead of sending the user directly to them?


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."

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜