1 Star 0 Fork 88

徐晨皓_0.0/ttt

forked from Admin/ttt 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
06.html 2.07 KB
一键复制 编辑 原始数据 按行查看 历史
Your Name 提交于 2022-06-24 16:19 . 期末
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
Notes: <select></select> <button>Add</button><br>
<textarea style="width: 100%"></textarea>
<script>
let list = document.querySelector("select");
let note = document.querySelector("textarea");
let state;
function setState(newState) {
list.textContent = "";
for (let name of Object.keys(newState.notes)) {
let option = document.createElement("option");
option.textContent = name;
if (newState.selected == name) option.selected = true;
list.appendChild(option);
}
note.value = newState.notes[newState.selected];
localStorage.setItem("Notes", JSON.stringify(newState));
state = newState;
}
setState(JSON.parse(localStorage.getItem("Notes")) || {
notes: { "shopping list": "Carrots\nRaisins" },
selected: "shopping list"
});
list.addEventListener("change", () => {
setState({ notes: state.notes, selected: list.value });
});
note.addEventListener("change", () => {
setState({
notes: Object.assign({}, state.notes,
{ [state.selected]: note.value }),
selected: state.selected
});
});
document.querySelector("button")
.addEventListener("click", () => {
let name = prompt("Note name");
if (name) setState({
notes: Object.assign({},state.notes, { [name]: "" }),
selected: name
});
});
</script>
</body>
</html>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/xu-chenhao-123/ttt.git
git@gitee.com:xu-chenhao-123/ttt.git
xu-chenhao-123
ttt
ttt
master

搜索帮助