我有6个div,其中2个有内容,它们隐藏或可见取决于点击2'隐藏'和2'的'div',请查看小提琴,看看我的意思。 / p>
page1.html
<div id="show-politics" class="topics">show</div>
<div id="show-technology" class="topics">show</div>
page2.html
<div id="hide-politics" class="topics">hide</div>
<div id="rss-feeds" class="me">contents</div>
<div id="hide-technology" class="topics">hide</div>
<div id="rss-feeds2" class="me">contents</div>
JS
$(document).ready(function($) {
if (Modernizr.localstorage) {
$('#hide-politics').click(function(e) {
localStorage.setItem('subscribed', true);
$('#rss-feeds,#hide-politics').hide();
$('#hide-politics').hide();
$('#show-politics').show();
});
$('#show-politics').click(function(e) {
localStorage.setItem('subscribed', true);
localStorage.clear();
$('#rss-feeds,#hide-politics').show();
$('#show-politics').hide();
});
var is_subscribed = localStorage.getItem('subscribed');
if (is_subscribed) {
console.log('localStorage');
$('#rss-feeds,#hide-politics').hide();
}
if (!is_subscribed) {
console.log('no localStorage');
$('#rss-feeds').show();
$('#show-politics').hide();
}
}
});
$(document).ready(function($) {
if (Modernizr.localstorage) {
$('#hide-technology').click(function(e) {
localStorage.setItem('subscribed2', true);
$('#rss-feeds2,#hide-technology').hide();
$('#hide-technology').hide();
$('#show-technology').show();
});
$('#show-technology').click(function(e) {
localStorage.setItem('subscribed2', true);
localStorage.clear();
$('#rss-feeds2,#hide-technology').show();
$('#show-technology').hide();
});
var is_subscribed2 = localStorage.getItem('subscribed2');
if (is_subscribed2) {
console.log('localStorage');
$('#rss-feeds2,#hide-technology').hide();
}
if (!is_subscribed2) {
console.log('no localStorage');
$('#rss-feeds2').show();
$('#show-technology').hide();
}
}
});
我需要'show'divs来自'hide'divs和内容divs的另一个页面,它们在同一页面上,这在某种程度上起作用,唯一的问题是,我不能只做1当'show'divs在另一个页面上时div可见,当我点击1'show'div时,所有隐藏的div变得可见而不是只有一个,但是当它们在同一页面上时,它们的行为方式与它们的假设相同就像小提琴一样,
你能看一下我的代码,看看是否有办法在单独的页面上让它在小提琴中的行为方式相同?
它使用modenizr本地存储