开发者

jQuery Dynamic Page Loading wont work, not sure why any ideas?

开发者 https://www.devze.com 2022-12-31 12:03 出处:网络
Live demo here <- http://webcallonline.exoflux.co.uk/html/ $(function() { var url = $(this).attr(\"href\");

Live demo here <- http://webcallonline.exoflux.co.uk/html/

    $(function() {
 var url = $(this).attr("href");
    $("nav").delegate("a", "click", function(event) {
     ev开发者_如何学Goent.preventDefault();
        window.location.hash = $(this).attr('href');
        $("#main").slideUp('slow', function(){
         $("#main").load(url + " #main", function()
      {
       $("#main").slideDown('slow');
      });
        });

    });

    $(window).bind('hashchange', function(){
     newHash = window.location.hash.substring(1);
    });

    $(window).trigger('hashchange');
});

Does anyone have any ideas?


This line:

var url = $(this).attr("href");

should be moved inside the click handler:

$("nav").delegate("a", "click", function(event) {
     var url = $(this).attr("href");
     event.preventDefault();

since you're loading content based on the href of the clicked anchor.

EDIT: or do you intend to get the current url?

var url = window.location.href;

?

0

精彩评论

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

关注公众号