点击按钮复制链接(实现点击按钮,复制文本框中的的内容)

想要的效果是,点击复制链接的按钮,然后就把事先准备好的链接复制上,然后crtr+v就能黏贴出来

 

我实在react的项目中使用的

// 复制链接方法
copyUrl() {
  let inputText = document.getElementById('inputText');
  let currentFocus = document.activeElement;
  inputText.focus();
  inputText.setSelectionRange(0, inputText.value.length);
  document.execCommand('copy', true);
  currentFocus.focus();
  if (document.execCommand('copy', true)) {
    Toaster.show({
      type: 'success',
      content: '复制链接地址成功'
    });
  }
}

 

//在进入页面的时候,就把链接准备好了

let copyUrl = 'http://f.xxx.com/priceList/detail/15?bpmCode='+self.state.bpmCode
self.setState({ copyBtnCuipiUrl: copyUrl }, () => {});
<input className="copyUrlInput" type="text" id="inputText" value={this.state.copyBtnCuipiUrl}/>
<Button className="copyUrlBtn" size="small" type="primary" onClick={this.copyUrl}>复制催批链接</Button>

 

//css 使得最开始的时候input框可以被button按钮给盖住

.copyUrl{
  float: right;
  .copyUrlInput{
    width: 20px;
    float: right;
    margin-right: 20px;
  }
  .copyUrlBtn{
    position: absolute;
    right: 20px;
  }
}
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值