javascript - 如何将表单提交的日期/时间推送到 Firebase 数据库
问题描述
我正在尝试将表单提交的日期和时间与用户输入的电子邮件一起推送。电子邮件通过但日期/时间没有。
到目前为止我已经尝试过了......
//Listen for form submit
document.getElementById('cta_form').addEventListener('submit', submitForm);
//Submit Form
function submitForm(e){
e.preventDefault();
//Get Valuse
var email = getInputVal('email');
var email_date = new Date();
console.log(email_date);
//save email
saveEmail(email,date);
//Show alert
document.querySelector('.alert').style.display = 'block';
//set alert timeout
setTimeout(function(){
document.querySelector('.alert').style.display = 'none';
},3000);
//Clear Form
document.getElementById('cta_form').reset();
}
//function to id values
function getInputVal(id){
return document.getElementById(id).value;
}
//Save emails to firebase
function saveEmail(email,email_date){
var newEmailRef = emailsRef.push();
newEmailRef.set({
email: email,
date: email_date,
});
}
我只想让日期像在 console.log 中一样显示。例如
Thu Aug 29 2019 22:18:47 GMT+0530 (India Standard Time)```
解决方案
您只需要将日期显式转换为字符串
function saveEmail(email,email_date){
var newEmailRef = emailsRef.push();
newEmailRef.set({
email: email,
date: "" + email_date,
});
}
推荐阅读
- python - 如何为可执行的 python 脚本包含可选输入?
- cefsharp - CEFSharp 的 ECCN(出口管制分类号)
- python - 检查变量是否是queryset django中的列表
- javascript - 如何验证shadow dom中的文本颜色?
- c# - 当仅从 xaml 引用时,为什么从已编译的程序集中删除程序集引用
- node.js - fs.createReadStream 获得的路径与传入的路径不同
- plugins - 需要帮助在 TeamCity 中使用插件 parasoft 发现发布 xml 报告
- api - 使用返回链接列表的 HAL API 端点的正确客户端实现是什么
- nltk - 为什么 WSD 不匹配 WordNet?
- java - Android:线程创建另一个单例实例