使用cookies,我想讓它記住頁面的顏色佈局。 (所以,如果他們設置的畫廊一個顏色和車身背景的另一種顏色,它會保存在刷新,但它似乎並不奏效記住頁面的顏色佈局
這裏是我的JavaScript代碼:。
$(document).ready(function() {
if (verifier == 1) {
$('body').css('background', $.cookie('test_cookie'));
}
if (verifier == 2) {
$('#gallery').css('background', $.cookie('test_cookie'));
}
if (verifier == 3) {
$('body').css('background', $.cookie('test_cookie'));
$('#gallery').css('background', $.cookie('test_cookie'));
}
$('#set_cookie').click(function() {
var color = $('#set_cookie').val();
$.cookie('test_cookie', color);
});
$('#set_page').click(function() {
$('body').css('background', $.cookie('test_cookie'));
var verifier = 1;
});
$('#set_gallery').click(function() {
$('#gallery').css('background', $.cookie('test_cookie'));
var verifier = 2;
});
$('#set_both').click(function() {
$('body').css('background', $.cookie('test_cookie'));
$('#gallery').css('background', $.cookie('test_cookie'));
var verifier = 3;
});
});
我的HTML:
<body>
<div id="wrap">
<div id="header">
<img src="media/header.png" alt="Community Header" />
</div>
<p>Please select a background color for either the page's background, the gallery's background, or both.</p>
<select id="set_cookie">
<option value="#1d375a" selected="selected">Default</option>
<option value="black">Black</option>
<option value="blue">Blue</option>
<option value="brown">Brown</option>
<option value="darkblue">Dark Blue</option>
<option value="darkgreen">Dark Green</option>
<option value="darkred">Dark Red</option>
<option value="fuchsia">Fuchsia</option>
<option value="green">Green</option>
<option value="grey">Grey</option>
<option value="#d3d3d3">Light Grey</option>
<option value="#32cd32">Lime Green</option>
<option value="#f8b040">Macaroni</option>
<option value="#ff7300">Orange</option>
<option value="pink">Pink</option>
<option value="purple">Purple</option>
<option value="red">Red</option>
<option value="#0fcce0">Turquoise</option>
<option value="white">White</option>
<option value="yellow">Yellow</option>
</select>
<input type="button" id="set_page" value="Page's Background" /><input type="button" id="set_gallery" value="Gallery's Background" /><input type="button" id="set_both" value="Both" />
</div>
</div>
</body>
</html>
下面是一個例子的jsfiddle:http://jsfiddle.net/hL6Ye/
如果您嘗試使用更具描述性的問題標題和reduc,則您有更好的機會獲得答案e你的片段中無關代碼的數量... – bobbymcr
@bobbymcr好吧謝謝,我會整理它。 –
您對「驗證者」的使用讓我感到困惑。 –