0

我有一个在一组复选框上运行的 javascript 来过滤通过 PHP 显示的一些项目。

当某人过滤信息然后单击一个项目时,他会被定向到该项目的描述。我的问题是当该用户单击浏览器中的“返回”按钮时,因为我的过滤已经消失了。

发生这种情况是因为我的脚本加载了 .php 但仅在 DIV 内(因此我不需要重新加载整个页面)。这意味着我发送的变量只是在 DIV 级别而不是在 URL 级别加载,因此当它们转到特定产品的描述然后返回时,这些变量不再存在并且过滤消失了。

这是我的 JS:

$(function() {
    $("input[type='checkbox']").on('change', function() {
        var boxes = [];
        // You could save a little time and space by doing this:
        var name = this.name;
        // critical change on next line
        $("input[type='checkbox'][name='"+this.name+"']:checked").each(function() {
            boxes.push(this.value);
        });
        if (boxes.length) {
            $(".loadingItems").fadeIn(300);
            // Change the name here as well
            $(".indexMain").load('indexMain.php?categ=<?php echo $category; ?>&'+this.name+'=' + boxes.join("+"),
            function() {
                $(".indexMain").fadeIn('slow');
                $(".loadingItems").fadeOut(300);
            });

        } else {
            $(".loadingItems").fadeIn(300);
            $(".indexMain").load('indexMain.php?categ=<?php echo $category; ?>', function() {
                $(".indexMain").fadeIn('slow');
                $(".loadingItems").fadeOut(300);
            });
        }
    });
});

有什么办法解决这个问题吗?

4

1 回答 1

0

在新窗口中打开项目描述,或者(更优雅地)在模式对话框中打开项目描述(例如使用jQuery UI 对话框)。

于 2013-02-14T23:32:42.457 回答