copyURL1(){
const links = document.getElementsByClassName("copylink" );`enter code here`
const range = document.createRange();
range.selectNode(links);
const selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
const successful = document.execCommand('copy');
}
我编写了从元素复制文本的代码,但是它显示'HTMLCollectionOf‘类型的错误参数不能分配给'Node’类型的参数。类型'HTMLCollectionOf‘缺少’Node‘类型中的下列属性: baseURI、childNodes、firstChild、isConnected和46更多。
发布于 2021-12-13 00:22:26
更改getElementsByClassName代码,这可能会有所帮助。
const links = document.getElementsByClassName("copylink" ).item(0);
参考文献:https://developer.mozilla.org/en-US/docs/Web/API/Range/selectNode
https://stackoverflow.com/questions/70331544
复制