日期:2014-05-16 浏览次数:20420 次
<script>
function addCss() {
$(this).css("color","red");
alert("addCss");
}
function removeCss() {
$(this).css("color","black");
alert("removeCss");
}
$(function() {$("#click").toggle(addCss,removeCss);});
</script>
<input id="click" type="button" value="click"></input>
//JS操作cookies方法!
//写cookies
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 (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();
}
//使用示例
setCookie("name","hayden");
alert(getCookie("name"));
<!DOCTYPE html>
<html>
<head>
<style>
body { margin:0; padding:0; font-size:12px; line-height:22px; background:#fff; }
.clearfix:after { content:' '; display:block; clear:both; height:0; font-size:0; visibility:hidden; }