最近做專案中牽扯到要寫一些cookie的例子,發現在自己在js方面還有很多的不足,然需要努力:
html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional/ /EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
無標題文件
<script><br/> function cookie(name, value, options) {<br/> if (typeof value != 'undefined') { // name and value given, set cookie<br/> options = options || {};<br/> if (value === null) {<br/> options.expires = -1;<br/> }<br/> var expires = '';<br/> if (options.expires.expire && (typeof options.expires == 'number' || options.expires.toUTCString)) {<br/> var date;<br/> date = new Date();<br/> date. setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));<br/> } }<br/> expires = '; expires=' + date.toUTCString() ; // use expires attribute, max-age is not supported by IE<br/> }<br/> var path = 0 s.domain ? '; domain= ' + options.domain : '';<br/> var secure = options.secure ? '; secure' : '';<br/> document.cookie = [ document。 .join('');<br/> } else { // only name given, get cookie<br/> var cookieValue = null;<br/> var cookies = document.cookie.split (';');<br/> for (var i = 0; i < cookies.length; i++) {<br/> // Does this cookie string begin with the name we want ?<br/> if (cookie.substring(0, name.length + 1) == (name + '=')) { .substring(name.length + 1));<br/> break;<br/> }<br/> }<br/> return cookieValue;<br/> }<br/>};<br/><p> $(document).ready(function(){<br/> if(cookie('show')==1)<br/> <br/> $(" #close").click(function(){<br/> $(".introBuy").css("display", 'none');<br/> );<br/> <br/>});<br/> </script>
關閉