首頁  >  問答  >  主體

如何保存在contenteditable div中輸入的文本,以便在重新載入HTML時重新顯示?

我不知道如何在設定了 'ContentEditable="true"' 的 div 中儲存一些文字?

基本上,我對 ​​HTML 和 CSS 編碼非常天真,而 JS 遠遠超出了我的能力範圍。不過,我已經成功地使用 HTML 和 CSS 為自己製作了某種日程安排表。

問題是,我不知道如何使放入 HTML 中的 div 中的文字(將 contenteditable 設為 true)保留下來,並在下次在瀏覽器上開啟 html 檔案時顯示。

我將只在本地主機中使用我的應用程序,並且不想使用任何類型的資料庫。

期待你們的專業知識和友善的幫助。 所需資訊如下--

.quote
{
    width: 92%;
    height: 48vh;
    margin: 2% auto auto auto;
    background-color: beige;
    border-style: solid;
    border-width: 12px;
    border-color: aqua;
    display: grid;
    grid-template-rows: 12% auto;
}

.quote .p
{
    height: 100%;
    margin:0 auto auto 12px;
    font-family: 'Montserrat', sans-serif;
    font-size: 12vh;
    background-image: linear-gradient(180deg, rgba(26,18,189,1) 51%, rgba(43,181,131,1) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.quote .p p
{
    height: 100%;
    width: 100%;
    margin:0;
}

.quote .writetext
{
    min-height: 8vmax;
    max-height: 19vmax;
    width: 25.6vmax;
    margin: 12px auto 12px auto;
    border-style: solid;
    border-width: 2px;
    border-color: white;

    font-family: 'Patrick Hand', cursive;
    font-size: 4vh;
    text-align: center;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>DayMaker- Welcome</title>
    <link rel="stylesheet" href="styles.css">
    <script src="scripts.js"></script>

    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Patrick+Hand&display=swap" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@-1,600&display=swap" rel="stylesheet">
</head>
<body>
     <div class="quote">
          <div class="p"><p>"</p></div>
          <div class="writetext" contenteditable="true">
          </div>
     </div>
</body>
</html>

注意:給定的程式碼片段是一個更大專案的一部分。因此,請忽略圖形差異。

這是我正在從事的專案的圖片:-我們需要修復右下角的那個框

我嘗試在網路上搜尋很多解決方案,但找不到任何解決方案。 真誠期待您的幫忙。

P粉156415696P粉156415696210 天前355

全部回覆(1)我來回復

  • P粉166779363

    P粉1667793632024-03-23 00:31:24

    你需要一個資料庫,我知道沒有資料庫就沒有辦法做到這一點,如果你在 SQL 方面遇到問題,你可以使用 Excel,否則除了使用資料庫之外我沒有解決方案

    回覆
    0
  • 取消回覆