html代码:
Js代码:
<script language="JavaScript" type="text/<a style=" color: text-decoration:underline title="javascript" href="https://www.php.cn/zt/15724.html" target="_blank">javascript"> <br>/* <br>* 设置Cookie的通用函数,其中name是必须的参数。其它为可选,故用条件语句判断。 <br>* 在设置Cookie时若不设置过期时间则该Cookie为临时的,仅当此次会话可用 <br>*/ <br>function setcookie(name, value, expires, path, domain, secure) { <br>var curcookie = name + "=" + encodeURI(value) <br>+((expires) ? ";expires=" + expires.toGMTString() : "") <br>+((path) ? ";path=" + path : "") <br>+((domain) ? ";domain=" + domain : "") <br>+((secure) ? ";secure" : ""); <br>document.cookie = curcookie; <br>} <br><br>//Cookie的写入 <br>function savecookie() { <br>var cookieInfo = document.frm1.cookieInfo.value; <br>var time = document.frm1.time.value; <br>var now = new Date(); <br>now.setDate( now.getDate() + time); <br>setcookie("myCookie",cookieInfo,now); <br>document.write(decodeURI(document.cookie)); <br>} <br><br>//读取所有Cooke <br>function writeAllCookie() { <br>document.cookie = "name1=" + encodeURI("名字1"); <br>document.cookie = "name2=" + encodeURI("名字2"); <br>document.cookie = "name3=" + encodeURI("名字3"); <br>var strInfo; <br>var cookie = document.cookie.split(";"); <br>for(var i=0; i<cookie.length; i++) { <br>var ck = cookie[i].split("="); <br>var cName = ck[0]; <br>var cValue = decodeURI(ck[1]); <br>strInfo += cName + "=" + cValue +"<br>"; <br>} <br>document.getElementById("divInfo").innerHTML = strInfo; <br>} <br><br>/* <br>* 读取特定Cookie的通用函数 <br>*/ <br>function getSpecificCookie(name) { <br>if(document.cookie.length > 0) { <br>start = document.cookie.indexOf(name + "="); <br>if( start != -1) { <br>start = start + name.length + 1; <br>end = document.cookie.indexOf(";",start); <br>if( end == -1) { <br>end = document.cookie.length; <br>} <br>} <br>return decodeURI(document.cookie.substring(start,end)); <br>} <br>return ""; <br>} <br><br>function getCk(){ <br>name = document.frm1.txtGetSpc.value; <br>alert( getSpecificCookie(name)); <br>} <br></script>










