javascript - 无法将 event.target 转换为字符串
问题描述
我有由Ant Design 表中event.target
的函数返回的:onRowClick
https://ant.design/components/table/#components-table-demo-colspan-rowspan
它的值是<a>ignissimos aper</a>
and 类型object
,这意味着它不能被字符串化。
event.target 上没有id
属性,所以我不能这样做:
如何将标签转换为字符串?
解决方案
如果您需要单击的行的数据,请使用 onRowClick 函数的第一个参数,该参数返回数据源的整个行对象。但是,如果您需要单击列的 innerHtml ,您可以这样做:
const onRowClick = (record, index, event) => {
console.log(record, index, event.target.innerHTML); // event.target.innerHTML is the innerHtml of the clicked column
};
推荐阅读
- vbscript - 如何使用经典的 ASP/VBScript 将图像转换为 Base64 字符串并保存到文本文件?
- javascript - 带有 Node.js 的 Docker 运行 -v 卷不起作用
- pytorch - 如何解决pytorch中的目标越界错误?
- powershell - Powershell 脚本未在 CSV 文件中显示 IP 地址
- flutter - Flutter:如何将项目的 ID 添加到字符串列表中
- daxstudio - Daxstudio 中的 Vertipaq Analyzer Metrix 窗格
- java - Java 下划线 - 在 Java 中将 JSON 转换为 XML
- android - 数据类动态改变可序列化名称
- javascript - 将重复数据发送到数组,然后检查所述数组是否为空,以决定接下来运行什么代码,如果语句不能正常工作
- python - Python Flask:拒绝服务器关闭时出错