繁体   English   中英

无法使用本地存储中的JavaScript填充电子邮件字段

[英]Cannot populate email field using JavaScript from local storage

我有两个文件test.html和test2.html我能够保存表单的值,但无法填写test2.html表单中的输入字段。

的test.html

    <script  type="text/javascript">
  function store(){
     var inputEmail= document.getElementById("email");

     localStorage.setItem("email", inputEmail.value);
    }
</script>
<form action="test2.html" class="form-login"  method="post" /> 
<input name="email" type="email" id="email" required="" placeholder="Email" />

<button onclick="store()" type="button">StoreEmail</button>

Test2.html

      <script type="text/javascript">
      function get(){

         var storedValue = localStorage.getItem("email");

         document.getElementById("email").innerHTML = storedValue;
         document.getElementById("email").value = storedValue;

        }
    </script>
    <p id="email">qqqqqq</p>
    <form action="" class="form-login"  method="post" /> 
    <input name="email" type="email" id="email" placeholder="Email" />

<button onclick="get()" type="button">getEmail</button>

当我点击getEmail按钮时,段落会发生变化,但电子邮件输入字段不会随值变化。 请帮忙。

每个DOM节点的id应该在整个DOM中是唯一的

document.getElementById始终返回第一个匹配的dom节点

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM