【发布时间】:2025-12-24 05:05:06
【问题描述】:
致所有了解 Firebase、HTML 和 Javascript 的人。
尝试使用 HTML 中的输入表单发布到 Firebase 数据库,但无法正常工作。
已设置数据库和所有内容,但未显示。没有返回错误。
你能帮帮我吗?
这是 HTML
<form id="recommendationForm">
<div class="row marketing">
<div class="input-group">
<span class="input-group-addon" id="sel0">Name</span>
<input type="text" class="form-control" placeholder="Ex.: 1832" aria-describedby="basic-addon1" id="os-input">
</div>
<div class="form-group">
<label for="sel1">Type:</label>
<select class="form-control" id="sel1">
<option selected value="1">Fixed</option>
<option value="2">Mobile</option>
</select>
</div>
<div class="form-group">
<label for="sel2">Technician:</label>
<select class="form-control" id="sel2">
<option selected value="1">Brandon</option>
<option value="2">Justin</option>
<option value="3">Ryan</option>
<option value="4">Tyler</option>
</select>
</div>
<br>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
然后是 .js 文件
/*
initializing firebase and getting values from input
then push the values and submit 'em
*/
$(function() {
var config = {
apiKey: "MY KEY",
authDomain: "MY AUTH",
databaseURL: "MY URL",
projectId: "MY ID",
storageBucket: "MY BUCKET",
messagingSenderId: "MY ID"
};
firebase.initializeApp(config);
var recommendations = firebase.database().ref("recommendations");
var submitRecommendation = function() {
// Get input values from each of the form elements
var value1 = $("#sel0").val();
var value2 = $("#sel1 option:selected").text();
var value3 = $("#sel2 option:selected").text();
// Push a new recommendation to the database using those values
recommendations.push({
"os": value1,
"datepicker": value2,
"estado": value3
});
$(window).load(function() {
// Find the HTML element with the id recommendationForm, and when the submit
// event is triggered on that element, call submitRecommendation.
$("#recommendationForm").submit(submitRecommendation);
});
};
});
这里是 JSFiddle https://jsfiddle.net/pimatco/dxhspx3o/
【问题讨论】:
标签: javascript html firebase firebase-realtime-database