【发布时间】:2017-06-11 19:20:50
【问题描述】:
我正在创建一个 HTML 页面,用户可以在其中更新他们的电子邮件地址。我附加了一个事件监听器,它将使用用户在表单中提供的电子邮件地址更新 Firebase。
下面的代码给出了一个错误:未捕获的类型错误:无法在 HTMLButtonElement 处读取 null 的属性“updateEmail”。
updateEmail 出现在 Firebase 文档中,所以我很困惑。有什么我想念的吗?感谢您的帮助!
Js
"use strict";
(function () {
// get the form elements from HTML
var acctEmail = document.getElementById('acctEmail'),
acctPassword = document.getElementById('acctPassword'),
btnUpdate = document.getElementById('btnUpdate'),
btnDeleteAcct = document.getElementById('btnDeleteAcct'),
auth = firebase.auth(),
user = firebase.auth().currentUser, // get the current user
emailtoval = acctEmail.value, // get the email from acctEmail input field
email = JSON.stringify(emailtoval); // convert email to json string
// update email
btnUpdate.addEventListener('click', function (e) {
user.updateEmail(email).then(function() {
// Update successful.
}, function(error) {
console.log(error);
});
});
})(); // end Js file wrapper
这是 HTML 表单:
<!DOCTYPE html>
<html>
<head>
<!-- head include -->
<% include includes/head.ejs %>
</head>
<body id="accountbody">
<!-- header include -->
<% include includes/header.ejs %>
<main>
<h1> Manage Your Account </h1>
<!-- begin account details form -->
<h2>Update your account</h2>
<div class="updateacctform">
<input id="acctEmail" type="email" placeholder="Email">
<input id="acctPassword" type="password"
placeholder="Password">
<button id="btnUpdate" class="updateacctbtn">Update
</button>
</div>
<div>
<h2>Delete your account</h2>
<button id="btnDeleteAcct" class="deleteacctbtn"> Delete
Account
</button>
</div>
</main>
<!-- footer include -->
<% include includes/footer.ejs %>
<!-- Js files -->
<script src="javascripts/account.js"></script>
</body>
</html>
【问题讨论】:
标签: javascript html firebase firebase-authentication