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

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

反應(yīng)錯誤:(函數(shù))未在 HTMLButtonElement.onclick 中定義

反應(yīng)錯誤:(函數(shù))未在 HTMLButtonElement.onclick 中定義

溫溫醬 2021-07-09 14:04:22
我正在使用 ReactJS,我正在一個名為的方法中創(chuàng)建一個“刪除”按鈕,showData()并將其附加到人員表中的一行。我設(shè)置其屬性,onclick我的方法removePerson()在同一類中的方法來實現(xiàn)showData()。這一切都很好,直到我單擊“刪除”按鈕 - 然后顯示錯誤:ReferenceError: removePerson() 未在 HTMLButtonElement.onclick 中定義這是我的代碼:showData() {        let localStoragePersons = JSON.parse(localStorage.getItem("personsForms"));        persons = localStoragePersons !== null ? localStoragePersons : [];        let table = document.getElementById('editableTable');        let x = table.rows.length;        while (--x) {            table.deleteRow(x);        }        let i = 0;        for (i = 0; i < persons.length; i++) {            let row = table.insertRow();            let firstNameCell = row.insertCell(0);            let lastNameCell = row.insertCell(1);            let birthdayCell = row.insertCell(2);            let salaryCell = row.insertCell(3);            let choclatesCell = row.insertCell(4);            let genderCell = row.insertCell(5);            let workTypeCell = row.insertCell(6);            let hobbiesCell = row.insertCell(7);            let descriptionCell = row.insertCell(8);            let colorCell = row.insertCell(9);            firstNameCell.innerHTML = persons[i].firstName;            lastNameCell.innerHTML = persons[i].lastName;            birthdayCell.innerHTML = persons[i].birthday;            salaryCell.innerHTML = persons[i].salary;            choclatesCell.innerHTML = persons[i].Choclates;            genderCell.innerHTML = persons[i].Gender;            workTypeCell.innerHTML = persons[i].workType;            hobbiesCell.innerHTML = persons[i].Hobbies;            descriptionCell.innerHTML = persons[i].Description;            colorCell.innerHTML = persons[i].favoriteColor;            colorCell.style.backgroundColor = persons[i].favoriteColor;            let h = persons[i].ID;        }    }
查看完整描述

1 回答

?
天涯盡頭無女友

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

當(dāng)您將變量設(shè)置為某個值時,首先計算該值。

因此,當(dāng)您寫出removeButton.onclick = this.removePerson(h);等式的右側(cè)時,首先對其進行評估。

您可以使用粗箭頭函數(shù)將其包裝起來,以便在用戶單擊時調(diào)用的函數(shù)將是調(diào)用this.removePerson(h). 這樣它的值是一個 lambda 函數(shù),而不是 的實際值this.removePerson(h)

removeButton.onclick = () => this.removePerson(h);


查看完整回答
反對 回復(fù) 2021-07-15
  • 1 回答
  • 0 關(guān)注
  • 753 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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