【问题标题】:jQuery Unwanted resetting of the DOM on history.back(-1)jQuery 在 history.back(-1) 上不需要的 DOM 重置
【发布时间】:2012-01-13 14:49:33
【问题描述】:

我在这个网站上使用了下面这个脚本http://ronnidc.dk...

当用户检查时,例如[jan] 一个点出现在下面的地图上。当用户单击该点时,包含指向子页面的阅读更多链接的预告文本会出现在地图下方。这一切都按预期工作。

问题 1: 问题是当用户通过(history-1)链接返回首页时。然后所有复选框都被清除,点和预告文本被设置回基础。除了在 Firefox 中——它在 Firefox 中完美运行。我猜这个问题与在 Firefox 以外的所有其他浏览器中重置 DOM 有关吗? (我希望当用户返回到带有地图的页面时,复选框选择、地图上的点和所选预告文本仍然可见)。

  我怎样才能避免这个问题?使用某种 .live 函数? (已从 jQuery 1.7 弃用)

问题 2: 当用户选中 [all] 时,所有复选框都按预期选中。但是为了有意义,当取消选中其他复选框之一时,复选框 [All] 的选择应该消失。 (其余选中的框应保持选中状态)

  如何做到这一点?

/**functions.js**/ 

$(document).ready(function () {

/* =Filtering - (mark the map with dots)
----------------------------------------------- */
    $(function () {

        $('#filtering :checkbox.checkall').click(function () {
            $(this).parents('fieldset:eq(0)').find(':checkbox').attr('checked', this.checked);
        });


            $("#filtering :checkbox").attr('checked', null); //uncheck checkboxes on page reload in Firefox
            $("#filtering :checkbox").click(function() {
                $("#pageTeaser article mark").hide();
                $("#filtering :checkbox:checked").each(function() {
                    $("." + $(this).val()).show();
                });
            });

    });



/* =Teaser Show - (Showing teaser text when clicking the dot's)
----------------------------------------------- */
    $('#pageTeaser article mark').click(function() {
        $('#pageTeaser article .inner').hide();
        $('#pageTeaser article .inner').removeClass('active');
        $(this).siblings('.inner').show();
        $(this).siblings('.inner').addClass('active');
    });

});

【问题讨论】:

    标签: javascript jquery dom browser-history


    【解决方案1】:

    您必须将该状态(所有复选框状态)存储在某处:cookie、location.hash、url ……也许history.js 可以在这里提供任何帮助。

    【讨论】:

    • 好的,我会仔细研究您建议的选项 - 谢谢
    • 当您访问 wonder 时,您会访问一个新页面,因此默认情况下不会保留以前的状态(firefox 很懒,我猜它会将页面保留在内存中,准备重新访问)
    猜你喜欢
    • 2013-05-15
    • 2014-05-12
    • 2013-01-26
    • 1970-01-01
    • 2012-01-28
    • 1970-01-01
    • 1970-01-01
    • 2019-02-16
    • 2021-03-07
    相关资源
    最近更新 更多