您好,我嘗試為我的網站制作一個日志系統面板。該代碼工作正常,因為如果您將文本寫入輸入字段,它就會顯示出來。但如果您重新加載頁面,它就會消失。所以我的問題是消失的文字。我想在輸入文本時執行此操作,以便頁面刷新時文本不會消失。知道如何做到這一點嗎?我也想這樣做,如果您在輸入字段中輸入文本并按添加按鈕,您輸入的文本將顯示在其他頁面上。我的意思是 /log/edit/index.html 中有一個頁面,并且文本應該出現在 /log/view/index.html 站點上。我知道這基本上是不可能的任務,但我認為如果您在文本字段中輸入的文本進入 .txt 文件并將其保存到 /log/logs.txt 然后 /log/view/index.html 讀取,這可能是可能的它并顯示 txt 文件中的文本。function newElement() { var li = document.createElement("li"); var inputValue = document.getElementById("myInput").value; var t = document.createTextNode(inputValue); li.appendChild(t); if (inputValue === '') { alert("Invalid log! You must write something"); } else { document.getElementById("myUL").appendChild(li); } document.getElementById("myInput").value = "";}ul {margin: 0;padding: 0;}/* Style the list items */ul li {cursor: pointer;position: relative;padding: 12px 8px 12px 40px;list-style-type: none;background: #eee;font-size: 18px;transition: 0.2s;/* make the list items unselectable */-webkit-user-select: none;-moz-user-select: none;-ms-user-select: none;user-select: none;}/* Set all odd list items to a different color (zebra-stripes) */ul li:nth-child(odd) {background: #f9f9f9;}/* Darker background-color on hover */ul li:hover {background: #ddd;}/* Style the header */.header {background-color: #0d1426;padding: 30px 40px;color: white;text-align: center;}/* Clear floats after the header */.header:after {content: "";display: table;clear: both;}/* Style the input */input {margin: 0;border: none;border-radius: 0;width: 75%;padding: 11px;float: left;font-size: 16px;}/* Style the "Add" button */.addBtn {padding: 13px;width: 250px;background: #d9d9d9;color: #555;float: left;text-align: center;font-size: 16px;cursor: pointer;transition: 0.3s;border-radius: 0;border-bottom: 1px solid transparent;}
使用 javascript 或 PHP 的 HTML 日志系統
茅侃侃
2023-08-24 17:50:27