【问题标题】:Fetch antd card value onclick in reactjs在reactjs中获取antd卡值onclick
【发布时间】:2021-01-28 06:15:05
【问题描述】:

我有一张由一些卡片组成的 antd gridstyle 卡片。当我点击特定卡片时,如何获取result function 中的内容?

点击标记卡,我想获取值Mark,但我不知道该怎么做。请提出解决方法。

import React from "react";
import ReactDOM from "react-dom";
import "antd/dist/antd.css";
import "./index.css";
import { Card } from "antd";

const gridStyle = {width: "25%",textAlign: "center"};
function result(){
  alert(1) // HOW CAN I GET "MARK" HERE??????  <---------------------
}
ReactDOM.render(
  <Card title="Card Title">
      <Card.Grid style={gridStyle} onClick={result}>Mark</Card.Grid>
      <Card.Grid style={gridStyle} onClick={result}>Jeff</Card.Grid>
  </Card>,
  document.getElementById("container")
);

【问题讨论】:

    标签: reactjs antd


    【解决方案1】:

    您可以在 result 函数中使用 event.target.innerText

    function result(event) {
      console.log(event.target.innerText) 
    }
    

    【讨论】:

      猜你喜欢
      • 2020-04-08
      • 2021-12-27
      • 1970-01-01
      • 2019-05-05
      • 2019-08-16
      • 2022-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多