【问题标题】:Remove Refresh Help Jquery删除刷新帮助 Jquery
【发布时间】:2009-06-18 01:42:34
【问题描述】:

我试图让 div 最近的活动仅在单击删除时刷新

删除

但是当我每次点击链接时,它都会尝试刷新。 当鼠标移到 tr 上时,会出现一个链接说 remove here is the code 。

$(function () {
    $("tr").hover(function () {
        var id = this.id.split('_').pop();
        $("#remove_" + id).show();
    }, function () {
        var id = this.id.split('_').pop();
        $("#remove_" + id).hide();
    });
});

这是您单击链接时发生的情况。

function remove_wall(id) {
    var refresh = setInterval(function () {
        $("#recent_activity").load("activity.php?random=" + unique_requestid());
    }, 1);

    $("#contentArea").load("remove.php?wall_id=" + id + "");
};

php 中的 remove 工作正常。

【问题讨论】:

    标签: php javascript jquery


    【解决方案1】:

    问题是您使用的是 setInterval - 每 x 毫秒重复一个函数,其中 x 是给定的时间间隔。

    您真正需要使用的是 setTimeout - 它将启动一个计时器,然后在计时器倒计时后运行,并且只运行一次。

    您的代码应如下所示:

    function remove_wall(id) {  
        var refresh = setTimeout(function() {
            $("#recent_activity").load("activity.php?random=" +unique_requestid());
        }, 1);
        $("#contentArea").load("remove.php?wall_id="+id+"");
    };
    

    进一步阅读链接:Timers with setTimeout and setInterval

    【讨论】:

      猜你喜欢
      • 2021-07-15
      • 1970-01-01
      • 2023-03-04
      • 2017-05-22
      • 1970-01-01
      • 1970-01-01
      • 2016-11-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多