我在cookie中存储了一个属性用于用户首选项,以获取cookie我使用以下代码:
function getCookie(cookieName) {
var cookieValue = null;
if (document.cookie) {
var arr = document.cookie.split((escape(cookieName) + '='));
if (2 <= arr.length) {
var arr2 = arr[1].split(';');
cookieValue = unescape(arr2[0]);
}
}
return cookieValue;
}
已使用:var userPref = getCookie("userPref");
然后我就像这样使用存储在cookie中的值,例如:
$('body').css('background-color', eval(userPref));
是否可以在不使用userPref
函数的情况下转换eval()
属性?