改變了我使用jQuery的功能,改變類元素如何記住它們的jQuery
$("a").click(function(){
$(this).closest("ul").find("a").parent().removeClass("active");
$(this).parent().addClass("active");
});
,但是當我刷新頁面,沒有加入改變HTML屬性的變化。即使用戶刷新頁面,如何記住它們?提前致謝。
改變了我使用jQuery的功能,改變類元素如何記住它們的jQuery
$("a").click(function(){
$(this).closest("ul").find("a").parent().removeClass("active");
$(this).parent().addClass("active");
});
,但是當我刷新頁面,沒有加入改變HTML屬性的變化。即使用戶刷新頁面,如何記住它們?提前致謝。
你需要使用某種類型的data store
(Cookies
,Local Storage
,QueryString
)來初始化active
項目。儘管如果您提供更多的上下文,可能會有另一個/更好的解決方案。基於關
更新評論:
嵌入在每個映射到一個標籤class
名稱或id
標籤一個隱藏的元素。然後創建一個簡單的算法,將當前顯示的選項卡內容與關聯的選項卡導航項匹配。
我正在使用引導標籤插件。並希望保存點擊標籤。那就是我想要做的。什麼是最簡單的方法? – Pavel 2012-02-15 22:31:04
「在每個標籤中嵌入一個隱藏的元素」,但是在刷新頁面之後該元素會便宜些?或者我忽略了一些錯誤? – Pavel 2012-02-15 22:41:41
*每個*選項卡鏈接都有一個與之關聯的內容區域。因此,在*每個內容區*中添加一個隱藏元素,該隱藏元素具有'class'name或'id',其值等於標籤鏈接類名稱。 – xandercoded 2012-02-15 22:45:20
使用此三種功能來存儲您的配置
localStorage.setItem("name", "Hello World!"); //saves to the database, key/value
localStorage.removeItem("name"); //deletes the matching item from the database
localStorage.getItem("name"); // gets the item back
thans for advise,但我有任務中的條件 - 不要使用html5。 – Pavel 2012-02-15 22:45:22
一般來說,在沒有服務器端應用程序的網站,用戶不要指望頁面狀態使用刷新頁面時保持。 – 2012-02-15 22:25:47