我有4个div的页面上具有唯一的ID。外部链接示例: www.website.com/page.html#one
。Javascript更改显示基于URL
我需要显示(设置为无)更改为阻止。我有点失落(我的JavaScript不是很强大)。有任何想法吗?以下是我用来修改网址的代码,并且div ID实际上只是one
,two
,three
和four
。
$(document).ready(function()
{
var hashVal = window.location.hash.split("#")[1];
$("#" + hashVal).style.display = 'block';
});
window.location.hash.slice(1)作品一样好用于获取哈希值。 –