我想将选中的单选按钮存储在本地存储中,以便在页面重新加载时,它将在重新加载时检查最后一次检查的项目。如何使用纯Javascript将选中的单选按钮的值存储在本地存储中?
HTML:
<h3>Seconds Display:</h3>
<p id="secondsHidingText">Hiding seconds extends battery life</p>
  <input type="radio" name="seconds" value="show" checked="checked">Show  
<input type="radio" name="seconds" value="hide">Hide
这是JavaScript我:
localStorage.setItem('seconds', options.seconds);
(运行时的保存按钮,我已经被点击)
而且
document.getElementById('seconds').value = localStorage.getItem("seconds");
(在docum上运行耳鼻喉科加载)
我得到以下错误:Uncaught TypeError: Cannot set property 'value' of null
如何存储和检索核对单选按钮,并从本地存储?如果可能的话,我正在寻找一个纯JS方法来完成这一点。
谢谢!
你在哪里在页面上调用JS?听起来像它无法通过id找到输入。你有一个小提琴或链接到实时页面? –
不知道我是如何忽略它的,但没有显示带'秒'标识的元素。 –
这里有一个网页的链接:https://barrydoyle18.github.io/remindMeConfig.html 请原谅嘿警报... –