用JavaScript设置cookie并获得Cookie我试图根据我在HTML中选择的CSS文件来设置cookie。我有一个带有选项列表的表单,以及不同的CSS文件作为值。当我选择一个文件时,它应该保存到一个cookie中大约一个星期。下次打开HTML文件时,应该是您选择的前一个文件。JavaScript代码:function cssLayout() {
document.getElementById("css").href = this.value;}function setCookie(){
var date = new Date("Februari 10, 2013");
var dateString = date.toGMTString();
var cookieString = "Css=document.getElementById("css").href" + dateString;
document.cookie = cookieString;}function getCookie(){
alert(document.cookie);}HTML代码:<form>
Select your css layout:<br>
<select id="myList">
<option value="style-1.css">CSS1</option>
<option value="style-2.css">CSS2</option>
<option value="style-3.css">CSS3</option>
<option value="style-4.css">CSS4</option>
</select></form>
3 回答
温温酱
TA贡献1752条经验 获得超4个赞
// sets the cookie cookie1document.cookie = 'cookie1=test; expires=Fri, 3 Aug 2001 20:47:11 UTC; path=/'// sets the cookie cookie2 (cookie1 is *not* overwritten)document.cookie = 'cookie2=test; expires=Fri, 3 Aug 2001 20:47:11 UTC; path=/'// remove cookie2document.cookie = 'cookie2=; expires=Thu, 01 Jan 1970 00:00:00 UTC ; path=/'
添加回答
举报
0/150
提交
取消