Files
ClassContent/历届学生/陈一航/项目/菜谱/Collection.html
2024-09-27 02:06:13 +08:00

55 lines
1.2 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<button>收藏</button>
<script src='//cdn.bootcss.com/jquery/3.1.1/jquery.min.js'></script>
<script>
// 当前要收藏的数据
const data = JSON.parse(localStorage.getItem("info"));
var likeData = [];
document.write(JSON.stringify(data))
$("button").on('click', function () {
console.log("status")
if (localStorage.getItem("like") !== null) {
console.log("status2")
// 收藏的数据
const like = JSON.parse(localStorage.getItem("like"));
var status = false // true 重复false 不重复
for (var i = 0;i<like.length;i++) {
if (like[i].id === data.id) {
status = true
break;
}
}
if (status) {
console.log("重复")
} else {
like.push(data)
localStorage.setItem("like", JSON.stringify(like))
}
} else {
likeData.push(data)
localStorage.setItem("like", JSON.stringify(likeData))
}
});
</script>
</body>
</html>