如何创建Cookie以记住Javascript指令
约翰·吉奥塔(JohnGiotta)在早些时候善意地给了我这段代码(关于堆栈溢出),以便在我的网站上实现一个“关闭样式”按钮(用于大学作业)如何创建Cookie以记住Javascript指令,javascript,html,css,cookies,Javascript,Html,Css,Cookies,约翰·吉奥塔(JohnGiotta)在早些时候善意地给了我这段代码(关于堆栈溢出),以便在我的网站上实现一个“关闭样式”按钮(用于大学作业) 函数nostyle(){ 对于(i=0;i 设置禁用的css\ucookie SetCookie('css_disabled', 'true', 100); 要读取cookie,请执行以下操作: function ReadCookie(cookieName) { var theCookie=""+document.cookie; var
函数nostyle(){
对于(i=0;i
设置禁用的css\u
cookie
SetCookie('css_disabled', 'true', 100);
要读取cookie,请执行以下操作:
function ReadCookie(cookieName) {
var theCookie=""+document.cookie;
var ind=theCookie.indexOf(cookieName+"=");
if (ind==-1 || cookieName=="") return "";
var ind1=theCookie.indexOf(";",ind);
if (ind1==-1) ind1=theCookie.length;
return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}
if (ReadCookie('css_disabled') == 'true') {...
确保var
你的变量,这样你就不会设置一个全局变量。在for循环中,它应该是var i=0
而不是i=0
谢谢,但是我如何在我的代码中实现这一点,这比我们今年讨论的要多两年,我只是对它的工作方式感兴趣,我会保存这个集合吗ie as css\u禁用,然后…..您需要在页面加载时首先读取cookie。如果未设置cookie,您将得到一个空字符串,并且不会禁用。如果用户禁用css,请将cookie设置为true。
SetCookie('css_disabled', 'true', 100);
function ReadCookie(cookieName) {
var theCookie=""+document.cookie;
var ind=theCookie.indexOf(cookieName+"=");
if (ind==-1 || cookieName=="") return "";
var ind1=theCookie.indexOf(";",ind);
if (ind1==-1) ind1=theCookie.length;
return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}
if (ReadCookie('css_disabled') == 'true') {...