zoukankan      html  css  js  c++  java
  • 请看用javascript设置和读取cookie的简单例子

                                       

    请看用javascript设置和读取cookie的简单例子

    请看下面用javascript设置和读取cookie的简单例子,现在的问题是,如果要设置的是一个cookie集,比如在cookie1集中有uname,uid两组信息,应该如何写呢?
    cookie("cookie1")("uname")="testuser"
    cookie("cookie1")("uname")="testuid"

    ------------------------------------------------------------------------
    <HTML>
    <BODY>
    设置与读取 cookies...<BR>
    <INPUT TYPE = BUTTON Value = "设置cookie" onClick = "Set()">
    <INPUT TYPE = BUTTON Value = "读取cookie" onClick = "Get()"><BR>
    <INPUT TYPE = TEXT NAME = Textbox>
    </BODY>
    <SCRIPT LANGUAGE="JavaScript">
    function Set(){
    var Then = new Date()
    Then.setTime(Then.getTime() + 60*1000 ) //60秒
    document.cookie = "Cookie1=测试数据;expires="+ Then.toGMTString()
    }

    function Get(){
    var cookieString = new String(document.cookie)
    var cookieHeader = "Cookie1="
    var beginPosition = cookieString.indexOf(cookieHeader)
    if (beginPosition != -1){
    document.all.Textbox.value = cookieString.substring(beginPosition
    + cookieHeader.length)
    }
    else
    document.all.Textbox.value = "Cookie 未找到!"
    }
    </SCRIPT>
    </HTML>

  • 相关阅读:
    CF1368F
    CF1083F
    AGC030F
    AGC030E Less than 3
    CF1083C
    CF526G
    CF1408
    CF1408H Rainbow Triples
    CF1408I
    AGC019E
  • 原文地址:https://www.cnblogs.com/winner/p/340837.html
Copyright © 2011-2022 走看看