zoukankan      html  css  js  c++  java
  • JavaScript cookie 【每日一段代码69】

    <html>
    <head>
    <script type="text/javascript">
    function getCookie(c_name)
    {
    if (document.cookie.length>0){
    c_start=document.cookie.indexOf(c_name + "=")
    if (c_start!=-1){
    c_start=c_start + c_name.length+1
    c_end=document.cookie.indexOf(";",c_start)
    if (c_end==-1) c_end=document.cookie.length
    return unescape(document.cookie.substring(c_start,c_end))
    }
    }
    return ""
    }

    function setCookie(c_name,value,expiredays)
    {
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays)
    document.cookie=c_name+"="+escape(value)+((expiredays==null)? "" : "; expires="+exdate.toGMTString())
    }

    function checkCookie()
    {
    username=getCookie('username')
    if (username!=null&username!=""){
    alert('Welcome again'+username+'!')
    }
    else{
    username=prompt('Please enter your name:',"")
    if (username!=null && username!=""){
    setCookie('username',username,365)
    }
    }
    }
    </script>
    </head>
    <body onLoad="checkCookie()">
    </body>
    </html>

  • 相关阅读:
    19_多态及引用类型的转化
    18_接口以及基本实现
    17_super关键字 超,基,父
    Static 关键字
    17_抽象类
    17_继承
    数 函数类 Math类
    ArrayList类 Arrays类 注释
    我的第一篇博客
    hdu 3478 Catch--二分图判断
  • 原文地址:https://www.cnblogs.com/naokr/p/2432425.html
Copyright © 2011-2022 走看看