我在cloud firestor中创建了一个数据库,所以现在我想通过输入字段向其中添加一些信息,当输入字段为空信息时存储问题并且catch函数不起作用,我该如何修复它,并进行catch功能工作。
这是代码:
HTML:
<div class="container">
<input type="text" placeholder="Enter the country" id="country-field" required>
<p class="selectPar">Enter City</p>
<input type="text" placeholder="Enter the city" id="city-field" required>
<p class="selectPar">Enter the place name</p>
<input type="text" placeholder="Enter the place name" id="placename-field" required>
<p class="selectPar">Enter Address</p>
<input type="text" placeholder="Enter the address" id="address-field" required>
</div>
</div>
<div id="btnFrmAlignSec">
<button id="btnFrm" type="button" onclick="AddToDataBase()">Send to admin</button>
</div>
JavaScript
函数添加到数据库(){
var inputCountry = document.getElementById("country-field").value;
var inputCity = document.getElementById("city-field").value;
var inputAddress = document.getElementById("address-field").value;
var inputNameofPlace = document.getElementById("placename-field").value;
// Add a new document in collection "cities"
db.collection("UsersShare").doc().set({
name:inputNameofPlace,
city:inputCity,
country:inputCountry,
address:inputAddress,
})
.then(function() {
console.log("Document successfully written!");
document.getElementById("reply").style.display="inline";
})
.catch(function(error) {
console.error("Error writing document: ", error);
});
}
子衿沉夜
料青山看我应如是
相关分类