我有2個過濾器:按位置和類型。每次我需要更新散列URL而不刷新頁面。我怎樣才能做到這一點?例如用於排序數據的多個(2)哈希URL參數
鏈接結構: site.com/about#location=12#type=188
感謝
我有2個過濾器:按位置和類型。每次我需要更新散列URL而不刷新頁面。我怎樣才能做到這一點?例如用於排序數據的多個(2)哈希URL參數
鏈接結構: site.com/about#location=12#type=188
感謝
第一分由#
哈希起牀到2項的數組: - :
var location = hashes.filter(function(i) { return i.startsWith('location'); });
var type = hashes.filter(function(i) { return i.startsWith('type'); });
如果location.length == 1
-
var hashes = window.location.hash.split('#');
那麼如果它們存在像你可以檢查並且與type
一樣,那麼它們被設置。
,那麼你可以更新/更換,如: -
location[0] = "location=" + 11;
type[0] = "type=" + 190;
最簡單的方式加入他們重新走到一起,包住一個心不是一套是將它們添加到一個新的陣列和join
。
var arr = [];
if(location.length == 1) arr.push(location[0]);
if(type.length == 1) arr.push(type[0]);
window.location.hash = arr.join('#');
對不起,我不能給你一個明確的答案,但你想要做的是使用HTML5歷史API https://css-tricks.com/using-the-html5-history-api/ –
我會用'site.com/about#{「filters」:{「location」:12,「type」:188}}'然後你可以很容易地閱讀和操縱變量 – DelightedD0D