react 点击复制文本


class Index extends Component {
  constructor(props) {
    super(props);
  }

  copyText = () => {
    var val = document.getElementById('text');
    window.getSelection().selectAllChildren(val);
    document.execCommand("Copy");
  }

  render() {
    return (
      <div>
        <div className="wrapper">
          <p id="text">复制成功!</p>
          <button onClick={this.copyText}>copy</button>
        </div>
      </div>
    );
  }
}
export default Index;

 

本文参考自: https://blog.csdn.net/qq_34790644/article/details/105641231


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM