我找到了两个使用Javascript获取cookie数据的函数,一个在w3schools.com上,一个在quirksmode.org上我想知道我应该使用哪一个?例如,我相信我读到某些浏览器分割;分号时出现问题?W3Schools的:function getCookie(c_name) { if (document.cookie.length > 0) { c_start = document.cookie.indexOf(c_name + "="); if (c_start != -1) { c_start = c_start + c_name.length + 1; c_end = document.cookie.indexOf(";", c_start); if (c_end == -1) c_end = document.cookie.length; return unescape(document.cookie.substring(c_start, c_end)); } } return "";}怪异模式:function readCokie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') c = c.substring(1, c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length); } return null;}
添加回答
举报
0/150
提交
取消