Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/402.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何自动复制输入的文本?_Javascript_Reactjs_Ecmascript 6 - Fatal编程技术网

Javascript 如何自动复制输入的文本?

Javascript 如何自动复制输入的文本?,javascript,reactjs,ecmascript-6,Javascript,Reactjs,Ecmascript 6,我正在使用react,我希望当用户单击图标或按钮时,url会复制到剪贴板,但在输入或文本区域中有另一个文本。。。让我解释一下: 我有这段代码(来自另一个关于stackoverflow的问题),但我想更进一步。假设文本区域中出现的代码不是我希望复制到剪贴板的代码,而是复制了包含该代码的url。代码如下: 类CopyExample扩展了React.Component{ 建造师(道具){ 超级(道具); this.state={copySuccess:'} } copyToClipboard=(e)

我正在使用react,我希望当用户单击图标或按钮时,url会复制到剪贴板,但在输入或文本区域中有另一个文本。。。让我解释一下:

我有这段代码(来自另一个关于stackoverflow的问题),但我想更进一步。假设文本区域中出现的代码不是我希望复制到剪贴板的代码,而是复制了包含该代码的url。代码如下:

类CopyExample扩展了React.Component{
建造师(道具){
超级(道具);
this.state={copySuccess:'}
}
copyToClipboard=(e)=>{
this.textArea.select();
document.execCommand('copy');
e、 target.focus();
this.setState({copysecsuccess:'Copied!'});
};
render(){
返回(
{
document.queryCommandSupported('copy')&&
复制
{this.state.copycsuccess&&'✓'}
}
this.textArea=textArea}
value='ABC123CD'
/>
);
}
}

您可以在
之前操作预期值。选择()

演示代码沙盒


哈哈哈哈,你让事情看起来很简单,非常感谢
this.textArea.value = `https://some-url/${this.textArea.value}/code`;
this.textArea.select();