1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 点击按钮复制链接(实现点击按钮 复制文本框中的的内容)

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

时间:2024-07-17 16:59:52

相关推荐

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

想要的效果是,点击复制链接的按钮,然后就把事先准备好的链接复制上,然后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 = '/priceList/detail/15?bpmCode='+self.state.bpmCodeself.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;}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。