所以下面的代码允许我补充一个电子邮件地址和密码时,我打提交张贴在盒子里。这是伟大的,但我想它也把它添加到所谓的“用户”,所以我每次添加一个用户名和密码的对象。它创建了一个新的用途(例如,用户1,用户2),并在其inputes的电子邮件和密码,每个用户。添加电子邮件地址和密码输入到jQuery的一个const/JS
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<style>
#userinfo {
width: 500px;
height: 500px;
border: 1px solid black;
color: black;
}
</style>
</head>
<body>
<form>
<input id="userEmail" type="email" placeholder="Email">
<input id="userPassword" type="password" placeholder="Password">
<button id="sub-btn" name="submit" class="btnAction">Add User</button>
</form>
<div id="userinfo">
<p></p>
</div>
<script type="text/javascript">
$('#sub-btn').click(function() {
const email = $('#userEmail').val();
const password = $('#userPassword').val();
const account = {
user1: [
email: '',
password: '',
]
};
console.log(account);
event.preventDefault();
if (email && password) {
// account.users.email.add(email); I know this isnt right but im guessing this is where the right code should go
$('#userinfo').html(email);
console.log(account);
}
})
</script>
</body>
</html>
欢迎堆栈溢出。你已经尝试过这么做了吗?请回顾[预计需要多少研究工作?](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users)。堆栈溢出不是一种编码服务。预计您会在发布之前研究您的问题,并尝试亲自编写代码***。如果你遇到* specific *,请回来并包含[Minimal,Complete和Verifiable示例](https://stackoverflow.com/help/mcve)以及你试用的内容摘要 – FluffyKitten