JS添加和获取Cookie
< ! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< html xmlns= "http://www.w3.org/1999/xhtml" >
< head>
< meta http- equiv= "Content-Type" content= "text/html; charset=utf-8" / >
< title> jquery设置浏览器缓存cookie提示内容显示隐藏< / title>
< meta name= "description" content= "jquery制作通过判断各种浏览器版本等,来设置各个浏览器缓存cookie,控制模块内容或区域在浏览器缓存cookie的情况下,是否显示或隐藏等操作。" / >
< / head>
< body>
< script src= "http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type= "text/javascript" > < / script>
< script type= "text/javascript" >
$ ( function ( ) {
$ ( '.WebDown .Close' ) . click ( function ( ) {
$ ( '.WebDown' ) . fadeOut ( 300 ) ;
if ( $ ( "#NotShow" ) . attr ( "checked" ) ) {
setCookie ( "Browse" , "idea" , '0' ) ;
}
} ) ;
var Sys = { } ;
var ua = navigator. userAgent. toLowerCase ( ) ;
var s;
( s = ua. match ( /msie ([\d.]+)/ ) ) ? Sys. ie = s[ 1 ] :
( s = ua. match ( /firefox\/([\d.]+)/ ) ) ? Sys. firefox = s[ 1 ] :
( s = ua. match ( /chrome\/([\d.]+)/ ) ) ? Sys. chrome = s[ 1 ] :
( s = ua. match ( /opera.([\d.]+)/ ) ) ? Sys. opera = s[ 1 ] :
( s = ua. match ( /version\/([\d.]+).*safari/ ) ) ? Sys. safari = s[ 1 ] : 0 ;
if ( getCookie ( "Browse" ) == "idea" ) {
$ ( '.WebDown' ) . hide ( ) ;
} else {
if ( s) {
$ ( '.WebDown' ) . fadeIn ( 200 ) ;
}
}
} ) ;
function getCookie ( name ) {
var start = document. cookie. indexOf ( name + "=" ) ;
var len = start + name. length + 1 ;
if ( ( ! start ) && ( name != document. cookie. substring ( 0 , name. length ) ) ) {
return null ;
}
if ( start == - 1 ) return null ;
var end = document. cookie. indexOf ( ';' , len ) ;
if ( end == - 1 ) end = document. cookie. length;
return unescape ( document. cookie. substring ( len, end ) ) ;
}
function setCookie ( name, value, expires, path, domain, secure ) {
var today = new Date ( ) ;
today. setTime ( today. getTime ( ) ) ;
if ( expires ) {
expires = expires * 1000 * 60 * 60 * 24 ;
}
var expires_date = new Date ( today. getTime ( ) + ( expires) ) ;
document. cookie = name+ '=' + escape ( value ) +
( ( expires ) ? ';expires=' + expires_date. toGMTString ( ) : '' ) +
( ( path ) ? ';path=' + path : '' ) +
( ( domain ) ? ';domain=' + domain : '' ) +
( ( secure ) ? ';secure' : '' ) ;
}
< / script>
< style type= "text/css" >
* { margin: 0 ; padding: 0 ; list- style- type: none; }
a, img{ border: 0 ; }
. WebDown{ width: 220 px; border: solid 1 px #ffbb76; margin: 30 px auto; }
. WebDown . tipbox{ position: relative; height: 50 px; background: #fffcef; padding: 10 px; font- size: 12 px; }
. WebDown . laba, . WebDown . Close, . WebDown . arrow{ background: url ( http: / / www. 17 sucai. com/ preview/ 1 / 2013 - 05 - 02 / cookie/ images/ tipboxbg. gif) no- repeat; }
. WebDown . laba{ display: block; float: left; width: 42 px; height: 39 px; overflow: hidden; background- position: - 27 px 0 ; margin: 5 px 0 0 5 px; }
. WebDown . tiptext{ float: left; margin- left: 15 px; display: inline; }
. WebDown . tiptext h3{ font- size: 16 px; color: #db7c22; font- family: "微软雅黑" , "宋体" ; height: 34 px; line- height: 24 px; }
. WebDown . tiptext p label{ color: #999 ; cursor: pointer; margin- left: 5 px; }
. WebDown . Close{ width: 14 px; height: 14 px; overflow: hidden; background- position: - 13 px 0 px; position: absolute; bottom: 10 px; right: 10 px; cursor: pointer; }
. WebDown . arrow{ display: block; width: 13 px; height: 7 px; overflow: hidden; background- position: 0 - 7 px; position: absolute; left: 15 px; top: - 7 px; }
< / style>
< div class = "WebDown" >
< div class = "tipbox" >
< span class = "arrow" > < / span>
< span class = "laba" > < / span>
< div class = "tiptext" >
< h3> 点击采集发布商品< / h3>
< p> < input type= "checkbox" id= "NotShow" / > < label for = "NotShow" > 以后不再显示< / label> < / p>
< / div>
< div class = "Close" > < / div>
< / div>
< / div>
< / body>
< / html>