作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个文本条目列表,后跟一个按钮:
<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/
我是一名优秀的程序员,十分优秀!