所以下面的代碼允許我補充一個電子郵件地址和密碼時,我打提交張貼在盒子裏。這是偉大的,但我想它也把它添加到所謂的「用戶」,所以我每次添加一個用戶名和密碼的對象。它創建了一個新的用途(例如,用戶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