- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用localStorage
制作一个简单的程序。我创建了一个按钮来重置 localStorage
中的所有数据。不幸的是,它不起作用,我不知道为什么。
这是我的代码:
<script>
var slot = localStorage.getItem("slot");
if (slot == null) {
slot = 10;
}
document.getElementById("slot").innerText = slot;
function reduceSlot() {
if (slot >= 1) {
slot--;
document.getElementById("slot").innerText = slot;
localStorage.setItem("slot", slot);
}
else {
document.getElementById('slot').innerText = "FULL";
document.getElementById("button1").style.display = "none";
}
}
document.getElementById("button1").onclick = reduceSlot;
function clearLocalStorage(){
localStorage.clear();
}
</script>
<body>
<p id="slot">10</p>
<a href="javascript:reduceSlot(1)" id="button1">Deduct</a>
<button onclick="clearLocalStorage()">Clear All</button>
</body>
我在网站中遵循了此代码,但它无法运行。我浏览的大多数网站都令人困惑。我需要帮助。
最佳答案
<button onclick="window.localStorage.clear();">Clear All</button>
这应该有效。
关于javascript - 我的 localStorage.clear();行不通,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19137137/
我正在尝试实现这个简单的幻灯片:http://codepen.io/rafaelcastrocouto/pen/doZNMo 但我没有成功,我不知道问题是什么,唯一显示的是幻灯片的最后一张图片,我添加
我对 Promise 还很陌生,我认为我没有正确理解它,因为我在代码中尝试它但没有成功。 我在 NodeJS 上有一个服务器,使用 Express 库和 express-promise var exp
为什么两个盒子都在右边,而不是居中对齐? fiddle :http://jsfiddle.net/gh76q/1/ 我尝试将方框 2 的位置更改为相对位置,它可以解决问题,但当鼠标悬停在方框 1 上时
这个问题在这里已经有了答案: scanf() leaves the newline character in the buffer (7 个答案) 关闭 4 年前。 如果我尝试这样的事情: int
这个问题在这里已经有了答案: scanf() leaves the newline character in the buffer (7 个答案) 关闭 4 年前。 如果我尝试这样的事情: int
我有一张我的小 table ,它似乎不起作用。 CSS 会告诉所有我想要的高度和宽度。我这样做的方式有误吗?或者我错过了什么? 为什么不是所有的边界都对齐? 表格、html 和 CSS 可以在这个 j
我正在尝试使用localStorage制作一个简单的程序。我创建了一个按钮来重置 localStorage 中的所有数据。不幸的是,它不起作用,我不知道为什么。 这是我的代码: var sl
我有一个 Div,我想做的是,当您将鼠标悬停在 div 1 上时,它会更改 div 2。 所以我可以通过 .div1:hover .div2 的 CSS 来做到这一点,这意味着当我将鼠标悬停在 1 上
出于某种原因,比较逻辑无法正常工作……它不会比较两个 NSDecimalNumber 对象。有时有效,有时无效。真的很奇怪。 if 语句适用于某些编译,有时则不然。这是正确的做法吗? 数据来自一个 j
我在 iOS 上使用 Phonegap 2.1.0。在我的 main.html 文件中,我使用 jQuery 加载了一些 html。 但是,我正在加载的其中一个 html 文件有自己的 Javascr
行不通,而嵌套
我一般不会嵌套像这样: The following: one two 我将使用 像那样嵌套反而。但是今天我用了但似乎 Emacs 和 Google Chrome 都会考虑外部 一看
我有 3 个框 (div-s)。 main-box里面有两个盒子。第一个 (Box1) 向右浮动,另一个 (Box2) 向左浮动。 两个框的高度都设置为 100%,所以当其中一个拉伸(stretch)
我是一名优秀的程序员,十分优秀!