繁体   English   中英

通过URL中的哈希标记加载页面上的AJAX调用会如何?

[英]do AJAX call on page load through hash tag in URL?

我正在使用同位素,这是jsfiddle: http : //jsfiddle.net/desandro/DA3wF/

或者,或者,我已设置的演示: http : //nerdi.net/isotope-test.html

有一个选项filter: selector

我如何通过过滤器,例如: index.html#green加载页面时将过滤到.green类? 这可能吗?

filter: (window.location.hash != '') ? '.' + window.location.hash.replace('#', '') : 'default'

这是一个if/then语句,用于检查当前哈希是否为空字符串。 如果是,则将filter设置为default否则将其设置为window.location.hash值(减去# )。

这样的URL index.html将导致将filter设置为default而这样的URL index.html#my-selector将导致将filter设置为.my-selector

更新

您的代码无法运行的原因实际上与我的代码没有任何关系,但这是我在您的网站上测试过的代码的更新版本:

$filterLinks.click(function(){
    var $this = $(this);

    // don't proceed if already selected
    if ( $this.hasClass('selected') ) {
        return;
    }

    $filterLinks.filter('.selected').removeClass('selected');
    $this.addClass('selected');

    // get selector from data-filter attribute
    var selector = $this.data('option-value');

    $container'.isotope({
        filter: selector
    });
});
filter: window.location.hash.replace('#', '.')

location.hash将返回“ #green”,我们只需将其替换为一个点即可得到“ .green”。

jsfiddle的示例,该示例还介绍了如何还基于哈希值更改所选链接。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM