Here is a solution using jQuery
$(document).ready(function () {
//$("#background").css("background-color",$.cookie("defaultColor"));
$("#background-change").change(function (event) {
var color = $(this).val();
$("#background").css("background-color",color);
//$.cookie("defaultColor",color);
});
});
The code will change the background based on the selected value in the dropdown list.
To set and retrieve cookie using jQuery, you have to use the jQuery Cookie Plugin
Use this code to set cookie
$.cookie("defaultColor",color);
Then use this code to retrieve cookie and set it as the backround color
$("#background").css("background-color",$.cookie("defaultColor"));
Check the Fiddle
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…