bob体育官方平台
新近项目写了部分js,水平有待抓牢_javascript技术_脚本之家

复制代码 代码如下:function ResumeError() { return true; } window.onerror = ResumeError; function showdd{ var dds = document.getElementById.getElementsByTagName; var len = dds.length; if(dds[0].style.display == "none"){ //该操作为展开菜单,需要判断cookie中是否有该项 //1、有,删除 //2、无,不执行操作 changeshowmenu; for(var i = 0; i < len;i++){ dds[i].style.display = ""; } }else{ //该操作为隐藏菜单,需要判断cookie中是否有该项: //1、有,不执行操作 //2、无,则要在末尾添加进去 changehidemenu; for(var i = 0; i < len;i++){ dds[i].style.display = "none"; } } } function changeshowmenu{ var temp = getcookie; if != "-1"){ temp = temp.replace addcookie; } } function changehidemenu{ var temp = getcookie; if == "-1"){ addcookie("openid",temp+obj+",",24); } } function getcookie {//取得cookie var aCookie = document.cookie.split; for (var j=0; j < aCookie.length; j++){ var aCrumb = aCookie[j].split; if return aCrumb[1]; } return null; } function addcookie(objName,objValue,objHours){//添加cookie var str = objName + "=" + objValue; if{//为0时不设定过期时间,浏览器关闭时cookie自动消失 var date = new Date(); var ms = objHours*3600*1000; date.setTime; str += "; expires=" + date.toGMTString(); } document.cookie = str; } //根据一个以逗号分开的字符串,初始化菜单哪些需要隐藏 function initmenu{ var arrmenu = obj.split; for(var i = 0; i < arrmenu.length;i++){ var dds = document.getElementById.getElementsByTagName; for(var j = 0;j < dds.length;j++){ dds[j].style.display = "none"; } } } function ${ return document.getElementById; } function delIt(){ var cbxBool = 0; for(var i = 0;i < cbxArray.length;i++){ var obj = $; if{ cbxBool = 1; break; } } if{ var result = confirm; if{ return true; } }else{ alert; return false; } return false; } window.onload = function(){ var lendl = document.getElementById.getElementsByTagName.length; if == null){ addcookie("openid","dl_c,dl_d,dl_e,dl_f,dl_g,dl_h,dl_i,dl_j,",24); } initmenu; var otable = document.getElementById; var trs = otable.getElementsByTagName; for(var i = 0;i < trs.length;i++){ trs[i].onmouseover = function(){ this.style.backgroundColor = "#F7F7F7"; } trs[i].onmouseout = function(){ this.style.backgroundColor = "#FFFFFF"; } } }

JS 新增Cookie 取cookie值 删除cookie 举例详解,jscookie

cookie很实用的一个功能,可以判断某个状态,在项目中使用率极高

复制代码 代码如下:

    function setCookie(name,value) 
    { 
        var Days = 30; 
        var exp = new Date(); 
        exp.setTime(exp.getTime() + Days*24*60*60*1000); 
        document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString(); 
        var strsec = getsec(time); 
        var exp = new Date(); 
        exp.setTime(exp.getTime() + strsec*1); 
        document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString(); 
    } 
    //读取cookies 
    function getCookie(name) 
    { 
        var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)"); 
        if(arr=document.cookie.match(reg)) 
            return (unescape(arr[2])); 
        else 
            return null; 
    } 
    //删除cookies 
    function delCookie(name) 
    { 
        var exp = new Date(); 
        exp.setTime(exp.getTime() - 1); 
        var cval=getCookie(name); 
        if(cval!=null) 
            document.cookie= name + "="+cval+";expires="+exp.toGMTString(); 
    } 

JS 怎 删除 一条 cookie?

js读取cookie,js添加cookie,js删除cookie,2008-09-26 10:02示例如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312" />
<title>cookie处理函数练习(为我所写,非我所想:改善面向对象)</title>
<script language="JavaScript" type="text/javascript">
function addCookie(objName,objValue,objHours){//添加cookie
var str = objName + "=" + escape(objValue);
if(objHours > 0){//为0时不设定过期时间,浏览器关闭时cookie自动消失
var date = new Date();
var ms = objHours*3600*1000;
date.setTime(date.getTime() + ms);
str += "; expires=" + date.toGMTString();
}
document.cookie = str;
alert("添加cookie成功");
}

function getCookie(objName){//获取指定名称的cookie的值
var arrStr = document.cookie.split("; ");
for(var i = 0;i < arrStr.length;i ++){
var temp = arrStr[i].split("=");
if(temp[0] == objName) return unescape(temp[1]);
}
}

function delCookie(name){//为了删除指定名称的cookie,可以将其过期时间设定为一个过去的时间
var date = new Date();
date.setTime(date.getTime() - 10000);
document.cookie = name + "=a; expires=" + date.toGMTString();
}

function allCookie(){//读取所有保存的cooki......余下全文>>  

返回顶部