javascript - 在网格 HTML/CSS/Javascript 中单击单元格时有一个弹出窗口
问题描述
我很难弄清楚这个问题。当单击 5x8 网格中的单元格时,我需要一个弹出窗口来显示。我需要从弹出窗口中将用户的信息输入到数据库中。我不需要直接的答案,但有没有办法解决这个问题?我对此很陌生。我可以使用任何技术来实现这一点。
感谢您的帮助。
解决方案
使用 JavaScript 向所有表格单元格添加事件侦听器,如下所示:
var cells = document.querySelectorAll('td');
cells.forEach((e)=>{
e.addEventListener("click", ()=>{
alert("cell clicked!");
})
})
td{
border:1px solid;
}
<table>
<tr>
<td>Table Cell</td>
<td>Table Cell</td>
<td>Table Cell</td>
<td>Table Cell</td>
<td>Table Cell</td>
<td>Table Cell</td>
<td>Table Cell</td>
<td>Table Cell</td>
</tr>
<tr>
<td>Table Cell</td>
<td>Table Cell</td>
<td>Table Cell</td>
<td>Table Cell</td>
<td>Table Cell</td>
<td>Table Cell</td>
<td>Table Cell</td>
<td>Table Cell</td>
</tr>
<tr>
<td>Table Cell</td>
<td>Table Cell</td>
<td>Table Cell</td>
<td>Table Cell</td>
<td>Table Cell</td>
<td>Table Cell</td>
<td>Table Cell</td>
<td>Table Cell</td>
</tr>
<tr>
<td>Table Cell</td>
<td>Table Cell</td>
<td>Table Cell</td>
<td>Table Cell</td>
<td>Table Cell</td>
<td>Table Cell</td>
<td>Table Cell</td>
<td>Table Cell</td>
</tr>
<tr>
<td>Table Cell</td>
<td>Table Cell</td>
<td>Table Cell</td>
<td>Table Cell</td>
<td>Table Cell</td>
<td>Table Cell</td>
<td>Table Cell</td>
<td>Table Cell</td>
</tr>
</table>
推荐阅读
- javascript - 如何在反应中打印包含在状态数组中的元素?
- html - 如何添加边框css
- java - Java,Eclipse,找不到或加载主类
- spring - 如何将 OrmLite DAO 实例自动装配到 Spring 控制器中?
- android - 如何避免房间外键错误 - 约束失败(代码 787)
- node.js - Passport.js 没有删除 req.logout() 上的会话
- spring - Spring Boot 中基于表达式的 Autowire(使用 Kotlin)
- java - 如何将 Java eclipse 插件项目导出到可执行 jar 文件?
- angularjs - 如何在angular js中实现显示更多按钮
- r - 在R中不同长度的两个向量中查找匹配值