4
我想保存在cookie多個變量,並已經和這是代碼:保存包含變量的多個值的Cookie?
function changeColors(){
//get the numbers from the html
var rd = parseInt(document.getElementById("red").value);
var gr = parseInt(document.getElementById("green").value);
var bl = parseInt(document.getElementById("blue").value);
var op = parseFloat(document.getElementById("opacity").value);
//convert the decimal into hexadecimal
var rdhex = (rd < 16) ? "0" + rd.toString(16) : rd.toString(16);
var grhex = (gr < 16) ? "0" + gr.toString(16) : gr.toString(16);
var blhex = (bl < 16) ? "0" + bl.toString(16) : bl.toString(16);
//concatenate all hex to generate a color
var hexcode = "#" + rdhex + grhex + blhex;
//view the change in the browser
document.getElementById("div").style.backgroundColor = hexcode;
document.getElementById("colordisplay").innerHTML = hexcode;
//change opacity
document.getElementById("div").style.opacity = op;
}
function WriteCookie()
{
if(document.myform.name.value == ""){
alert("Enter some value!");
return;
}
cookievalue= escape(document.myform.red.value) + ";" +
escape(document.myform.red.value)+ ";"+
escape(document.myform.green.value)+ ";"+
escape(document.myform.blue.value)+ ";"+
escape(document.myform.opacity.value)+ ";";
document.cookie="color=" + cookievalue;
alert("Setting Cookies : " + "color=" + cookievalue);
// To revise!!!How do we set multiple values to one cookie?
function ReadCookie()
{
var allcookies = document.cookie;
alert("All Cookies : " + allcookies);
// Get all the cookies pairs in an array
cookiearray = allcookies.split(';');
我需要存儲的名稱,RGB和不透明度在cookie中,這樣以後用戶可以從以前的選擇他管理自己的顏色。我的問題是如何將var hexcode和opacity與顏色的名稱一起存儲在cookie中?