[英]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.