单击按钮时解析元素

时间:2018-09-12 11:56:33

标签: reactjs ecmascript-6 react-props

因此,我想在点击“选择”按钮后解析h2标签并将其文本内容保存为常量

load = pd.concat([load] * 1000, ignore_index=True)

In [106]: %timeit load['print'] = load.apply(lambda x:(x.B>x.C)&(x.C==x.D)&(x.C!=0)&(x.D!=0),axis=1)
408 ms ± 13.3 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

In [107]: %timeit load['print'] = load.B.gt(load.C) & load.C.eq(load.D) & load['C'].ne(0) & load['D'].ne(0)
1.64 ms ± 135 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)

点击按钮后我用来设置状态的函数

<div className={"card " + (this.state.selected ? "methodSelected" : "")}>
    <h2 className="charge"></h2>
    <button onClick={this.selectMethod} href="#"className="btn return-btn">SELECT</button>
</div>

2 个答案:

答案 0 :(得分:1)

在selectMethod方法中,您可以添加-

selectMethod = () => {
  this.setState({selected: true});
  let x = document.getElementByClassName("charge").textContent;
  // doing something with the variable 'x'

}

答案 1 :(得分:0)

根据我对问题的理解,可以通过以下方式完成

selectMethod = () => {
      document.getElementById('heading').innerHTML="sample text"
      this.setState({selected: true});
  }

还将id属性添加到标题标签为

<h2 id="heading"></h2>