第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用按鈕單擊事件時,F(xiàn)irestore 不會添加新記錄(網(wǎng)絡(luò))

使用按鈕單擊事件時,F(xiàn)irestore 不會添加新記錄(網(wǎng)絡(luò))

瀟湘沐 2023-04-01 15:14:40
我是 Firebase Firestore 的新用戶。我有一個集合(“詞匯”),我想添加新文檔(“單詞”、“含義”)。該代碼有效并添加了新記錄。但是當我使用相同的代碼在單擊按鈕后執(zhí)行時,它不起作用并且沒有錯誤代碼。當我在 click 函數(shù)下編寫 Alert("test") 以測試是否被調(diào)用時,我看到“test”消息沒有問題。我認為,它表明監(jiān)聽器在點擊時被調(diào)用。但我認為 add() 部分沒有被調(diào)用??赡艿脑蚴鞘裁??此代碼有效:      database.collection("vocabulary").add({        word:"Book",        meaning:"xxx",      })      .then(function() {        console.log("Document successfully written!");      })      .catch(function(error) {        console.error("Error writing document: ", error);      });但相同的代碼在按鈕單擊下不起作用:<button id="savebutton">Insert Record</button>......const save=document.querySelector("#savebutton");  save.addEventListener("click",function() {       database.collection("vocabulary").add({        word:"Book",        meaning:"xxx",      })      .then(function() {        console.log("Document successfully wriiten!");      })      .catch(function(error) {        console.error("Error writing document: ", error);      });    }); 
查看完整描述

1 回答

?
jeck貓

TA貢獻1909條經(jīng)驗 獲得超7個贊

OP 通過添加以下代碼解決了該問題:


x.preventDefault();

從我收集的內(nèi)容來看,更新后的代碼看起來像這樣:


<button id="savebutton">Insert Record</button>

? ? ......


const save=document.querySelector("#savebutton");

? save.addEventListener("click",function(x) {

? x.preventDefault();?

? ? ? database.collection("vocabulary").add({

? ? ? ? word:"Book",

? ? ? ? meaning:"xxx",

? ? ? })

? ? ? .then(function() {

? ? ? ? console.log("Document successfully wriiten!");

? ? ? })

? ? ? .catch(function(error) {

? ? ? ? console.error("Error writing document: ", error);

? ? ? });

? ? });

因此,根據(jù)公共文檔,OP 阻止了“x”的默認操作,解決了這個問題。



查看完整回答
反對 回復(fù) 2023-04-01
  • 1 回答
  • 0 關(guān)注
  • 121 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號