2

我正在将此脚本用于 JQuery 中的选项卡

<script type="text/javascript">
$(function () {
var tabContainers = $('div.tabs > div');

$('div.tabs ul.tabNavigation a').click(function () {
    tabContainers.hide().filter(this.hash).show();

    $('div.tabs ul.tabNavigation a').removeClass('selected');
    $(this).addClass('selected');

    return false;
}).filter(':first').click();
});
</script>

但我真的很想知道如何使用该代码而不使用任何其他插件来保存选项卡的状态,知道吗?

4

2 回答 2

1

If you don't want to use an external code or plugin and don't mind not supporting IE 7, you could always use Local Storage. It's new to HTML 5 and allows you simply to save key value pairs to the browsers local storage using javascript. So if you wanted to save the value 'foo' under the key 'bar' you could do something as simple as:

localStorage.setItem("foo", "bar");

And to retrieve

var foo = localStorage.getItem("foo");

This website shows you what its supported on:

http://caniuse.com/#search=localstorage

And this is a good page for learning a bit about it:

https://developer.mozilla.org/en/DOM/Storage

There are two options with local storage

  • Local storage - This is persisted beyond page refreshes
  • Session storage - This is persisted while the browser session is still active. When you close your browsers tab, the storage is lost.

Hope this help[s!

Andy

于 2012-06-01T07:46:39.067 回答
1

我建议研究类似store.js的东西。它将允许您在给定域的客户端存储信息,并在后续页面加载时检索它。

于 2012-06-01T07:23:46.057 回答