我编写了一个 HTML 文件,它包含两个输入框,一个称为用户名,另一个称为密码。像这样的东西:
<input class='registerinput' id='registerusername' placeholder='Username'></input>
<input class='registerinput' id='registerpassword' placeholder='Password' type='password'></input>
<input class='registerinput' id='registerpasswordrepeat' placeholder='Repeat Password' type='password'></input>
我想使用这些代码将它存储到本地存储中。
if (document.getElementById('registerusername').value != "") {
localStorage.username=document.getElementById('registerusername').value }
else if (document.getElementById('registerusername').value == "") {
alert('You must enter a username.') }
if (document.getElementById('registerpassword').value != "" && document.getElementById('registerpasswordrepeat').value == document.getElementById('registerpassword').value) {
localStorage.password==document.getElementById('registerpassword'.value) }
else if (document.getElementById('registerpassword').value == "") {
alert('You must enter a password') }
if (document.getElementById('registerpasswordrepeat').value != document.getElementById('registerpassword').value) {
alert('The password did not match.') }
一切正常,除了我无法将值保存在密码框中。是 HTML5 的安全性存储限制还是我的代码中的错误?谢谢。