我想知道如何在刷新页面后保持"标记为已读"和"标记为未读"的状态.反之亦然.如何使用本地存储保存数据?到目前为止,这是我对"Mark as Read"的代码:
function readunread() {
currentvalue = document.getElementById("readunread").value;
if(currentvalue == "Mark as Unread"){
document.getElementById("readunread").value = "Mark as Read";
} else{
document.getElementById("readunread").value = "Mark as Unread";
}
}
body {
background:black;
}
.button {
border: none;
color: white;
font-family: Corbel;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
background-color: black;
}
input[type=button] {
font-size: 20px;
font-family: Corbel;
text-decoration: none;
color: white;
border: none;
background: none;
cursor: pointer;
margin: 0;
padding: 0;
}
<input type = "button" value = "Mark as Read" id = "readunread" onclick = "readunread();">
我点击"标记为已读",它变成了"标记为未读".但在刷新页面后,它将返回到"标记为已读".我怎么才能避免这种情况?