【发布时间】:2022-12-11 00:16:46
【问题描述】:
我正在使用 JavaScript 生成动态表,每行的最后一列都有一个“getCutomerEmail”按钮。现在我想在单击同一行上的“getCutomerEmail”按钮时提取电子邮件值。
我在 Preload.js 上声明了两个函数来提取电子邮件并将其发送到 main.js 以进行进一步处理:
function getEmail (el) {
const tr = el.closest("tr");
const tds = tr.getElementsByClassName('email');
const emailAddress = tds[0].innerHTML;
console.log(emailAddress);
ipcRenderer.send("ClickRunCH", emailAddress);
}
window.addEventListener('DOMContentLoaded', () => {
function renderCustomers(tasks) {
customerList.innerHTML += `
<tr >
<th >Name</th>
<th >Email</th>
<th >Contacts</th>
<th >Address</th>
<th >Country</th>
<th >Action</th>
</tr>`;
tasks.forEach((t) => {
customerList.innerHTML += `
<tr class=" animated bounceInUp">
<td >${t.Name}</td>
<td >${t.Email}</td>
<td >${t.Contacts}</td>
<td >${t.Address}</td>
<td >${t.Country}</td>
<td ><button class="email" onclick="getEmail(this)">
Get Customer Email
</button></td>
</tr>`;
});
})
但我收到此错误消息:
ReferenceError: getEmail is not defined
at HTMLButtonElement.onclick
非常感谢任何帮助,感谢阅读
【问题讨论】:
标签: javascript html html-table electron