假设我有一个长字符串:
"Jackie has a very big chicken at his farm"
突出显示字符串中的“chicken”并按ctrl+C,
它将触发handleCopy
函数,该函数传递到元素的onCopy
属性中。我希望复制子字符串或字符串的值,在本例中为“chicken”。例如,
function handleCopy(event){
//get the copied value here
}
<input value="Jackie has a very big chicken at his farm" onCopy={handleCopy} />
我如何能够在React中实现这一点?
1条答案
按热度按时间zengzsys1#
您可以对它使用copy event和
getSelection
方法,如docs示例所示...