【问题标题】:I have written code to copy the link from box but is it showing me the following error我已经编写了从框中复制链接的代码,但它是否向我显示以下错误
【发布时间】:2022-01-16 17:48:02
【问题描述】:
    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 个以上。

【问题讨论】:

    标签: javascript html css angular typescript


    【解决方案1】:

    更改 getElementsByClassName 代码,这可能会有所帮助。

    const links = document.getElementsByClassName("copylink" ).item(0);
    

    参考: https://developer.mozilla.org/en-US/docs/Web/API/Range/selectNode

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-23
      • 2021-08-14
      • 2022-11-20
      • 2022-12-03
      • 2022-10-25
      • 2021-09-30
      相关资源
      最近更新 更多