<div id="body-container">
<form id="user" action="login.html">
<input type="text" id="firstname" placeholder="Enter your First Name">
<input type="text" id="lastname" placeholder="Enter your Last Name">
<input type="number" id="age" placeholder="Enter your Age">
<select id="gender"" name="gender">
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
<input type="text" id="username" placeholder="Enter your Username">
<input type="password" id="password" placeholder="Enter your Password">
<br> <br>
<input type="submit" value="Submit" onclick="register()">
</form>
</div>
<footer id="footer">
<p>Created on November 2019, by <a href = "http://Jon_Doe.com>John Doe</a></p>
</footer>
<script>
function register(){
var firstname = document.getElementById("firstname").value
var lastname = document.getElementById("lastname").value
var age = document.getElementById("age").value
var gender = document.getElementById("gender").value
}
</script>
我必须从函数register()传输所有捕获的数据,并将其保存在名为“user”的对象中,然后将该数据保存到sessionStorage。
1条答案
按热度按时间enxuqcxy1#
您可以使用以下数据创建对象:
并使用
sessionStorage.setItem("user", JSON.stringify(user))
存储