在我的表格中,我有幾個復選框。所有選中的復選框值都應寫入 firebase 資料庫。但是,不能操縱復選框。我的代碼不采用復選框值。它不會出現在 Firebase 上。我的表單看起來像這樣 [![Form][1]][1] [1]:https://i.stack.imgur.com/8FEN4.png
HTML 代碼
<td>
<label>
<input class="paint" id = "paint" value="Anti-Fungus Paint" type="checkbox" unchecked> Anti-Fungus Paint
</label>
<label>
<input class="paint" id = "paint" value="Emulsion Paint" type="checkbox" unchecked> Emulsion Paint
</label>
<label>
<input class="paint" id = "paint" value="Anti-Corrosive Paint" type="checkbox" unchecked> Anti-Corrosive Paint
</label>
<label>
<input class="paint" id = "paint" value="All in one Paint" type="checkbox" unchecked> All in one Paint
</label>
</td>
Javasript
document.getElementById('formBid').addEventListener('submit',function(e){
e.preventDefault();
var id=Date.now(); //generating a unqiue id
set(ref(db,'quotes/' id),{
paint:document.querySelectorAll('input[id="paint"]:checked'),
});
alert('Quote Sent To Client');
formBid.reset();
uj5u.com熱心網友回復:
首先,您應該區分每個復選框的 id,該 id 應該是唯一的才能使其作業。我通常使用 getElementById 來獲取每個值,因為它對我來說更容易。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/496532.html