gpt4 book ai didi

javascript - 如何在 Angular2 中选择文本

转载 作者:行者123 更新时间:2023-12-01 03:50:47 24 4
gpt4 key购买 nike

我有一个文本条目列表,后跟一个按钮:

<li *ngFor="let match of matches; let i = index">
{{ match}} <button (click)="select(i)">Copy</button>
</li>

当用户单击按钮时,我想将文本复制到剪贴板。

  public select(index:any){
document.execCommand("copy");
}

这确实有效,但是,我必须首先选择相应文本的文本。我怎样才能在 Angular2 中做到这一点?

最佳答案

请参阅 How can I copy to clipboard in HTML5 without using flash? 中的答案

这个问题很老了,但前提是一样的。该标准禁止您在未明确同意要复制的内容的情况下使用用户的剪贴板。您无法跳过选择过程。不同浏览器的实现有所不同,但几乎都是相同的。

了解更多:https://developers.google.com/web/updates/2015/04/cut-and-copy-commands

关于javascript - 如何在 Angular2 中选择文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43225331/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com