相关疑难解决方法(0)

设置cookie并使用JavaScript获取cookie

我正在尝试根据我在HTML中选择的CSS文件来设置cookie.我有一个包含选项列表的表单,以及不同的CSS文件作为值.当我选择一个文件时,它应该保存到cookie大约一个星期.下次打开HTML文件时,它应该是您选择的上一个文件.

JavaScript代码:

function cssLayout() {
    document.getElementById("css").href = this.value;
}


function setCookie(){
    var date = new Date("Februari 10, 2013");
    var dateString = date.toGMTString();
    var cookieString = "Css=document.getElementById("css").href" + dateString;
    document.cookie = cookieString;
}

function getCookie(){
    alert(document.cookie);
}
Run Code Online (Sandbox Code Playgroud)

HTML代码:

<form>
    Select your css layout:<br>
    <select id="myList">
        <option value="style-1.css">CSS1</option>
        <option value="style-2.css">CSS2</option>  
        <option value="style-3.css">CSS3</option>
        <option value="style-4.css">CSS4</option>
    </select>
</form>
Run Code Online (Sandbox Code Playgroud)

html javascript css cookies

486
推荐指数
4
解决办法
95万
查看次数

如何在 astro 中将服务器变量传递给客户端 JS?

我找到了这个github) google auth 的 html 起始页,我想将其制作成 astro 组件。我想将其转换为.astro文件,并能够从后端传递 CLIENT_ID 和 API_KEY 的变量。我

这是来自谷歌的 HTML 代码:

<!DOCTYPE html>
<html>
  <head>
    <title>Google Calendar API Quickstart</title>
    <meta charset="utf-8" />
  </head>
  <body>
    <p>Google Calendar API Quickstart</p>

    <!--Add buttons to initiate auth sequence and sign out-->
    <button id="authorize_button" onclick="handleAuthClick()">Authorize</button>
    <button id="signout_button" onclick="handleSignoutClick()">Sign Out</button>

    <pre id="content" style="white-space: pre-wrap;"></pre>

    <script type="text/javascript">
      /* exported gapiLoaded */
      /* exported gisLoaded */
      /* exported handleAuthClick */
      /* exported handleSignoutClick */

      // TODO(developer): Set to …
Run Code Online (Sandbox Code Playgroud)

astrojs

17
推荐指数
1
解决办法
1万
查看次数

标签 统计

astrojs ×1

cookies ×1

css ×1

html ×1

javascript ×1