jquery - Can I use jQuery to have users add/remove content to a site?
问题描述
I want to be able to have users edit a list on a website and have the data they enter stay there after refresh. I have this code to add and remove data -
HTML -
<div class="list-editor">
<ul class="my-list">
<li><span>My to-do</span> <a href="#" class="delete">[done]</a></li>
</ul>
<input type="text" name="new-item" /> <button class="button">Add an item</button>
</div>
jQuery -
$(".list-editor").on("click", "button", function(){
let val = $("input[type='text']").val()
$(".my-list").append(`<li>${val} <a href="#" class="delete">[done]</li>`)
$("input[type='text']").val('Enter Text')
})
$(".list-editor").on('click','.delete',function() {
$(this).parent().css("text-decoration", "line-through")
})
What can I add to my jQuery code to get the data entered to remain on the site after refresh?
解决方案
推荐阅读
- android - 在 RecyclerView OnItemClickListener 上显示对话框
- flutter - 如何将下载的数据从 API 保存到 Flutter 中的 RAM?
- python - Django 自动建模多对多关系添加
- r - 如何计算期权的 Black-Scholes 看跌期权
- sorting - Kotin 按降序然后升序排序
- javascript - 仅 http cookie 中的 JWT 未定义
- c# - 附加 CSV 文件以回复 Microsoft Bot Framework for Teams
- google-cloud-platform - Google Speech to Text - LongRunningRecognize - PollUntilCompleted 返回购买操作仍未完成
- node.js - Apollo GraphQL Server 中的别名字段
- html - 视差效果 - 使部分出现在前一部分后面而不移动内容