首页 > 解决方案 > 如何使用 React 和 iframe 在点击时获取 className?

问题描述

我想获取我在 iframe 中单击的任何内容的类名。

const getClassName = (e) => {
  console.log(...)
}

<iframe src="somewikipediapage"/> 

标签: reactjs

解决方案


这篇文章之后,您可以使用此功能:

getNameOfChildrenClass() {
   const singleChild = React.children.only(this.props.children),
      childClass = child.type

   return childClass.name        
}

推荐阅读