0

由于 JQuery 是生活中所有事情的解决方案,因此我.load()在单击某个类的链接后使用它来加载具有该功能的页面,请参见下面的代码:
$('.pageloader').click(function(){ $('.content').load("pages/" + this.name); });

但是,这会在每次点击后加载两倍的页面数量(第一次 1,之后 2,4、8、16 等)。

我试过关闭所有其他代码,但它没有改变任何东西。使用 console.log 我注意到它只执行.click()一次该功能,并且它.load()被执行了多次。

有谁知道这可能是什么原因造成的?

4

2 回答 2

1

您可能绑定了几次点击事件......

在之前添加.click

$('.pageloader').unbind('click').off('click');
$('.pageloader').click(function(){ $('.content').empty().load("pages/" + this.name); });

[编辑]

问题出在加载的页面中。

于 2013-04-04T11:14:22.430 回答
1

试试这个:

$('.pageloader').click(function () {
    // Cache this here
    var $this = $(this);

    // Removes all child nodes (including text nodes) from content class
    $('.content').empty().load("pages/" + $this.attr('name'));
});
于 2013-04-04T11:14:57.573 回答