首页 > 其他 > 详细

点击复制指定内容

时间:2020-01-02 12:51:40      阅读:86      评论:0      收藏:0      [点我收藏+]

项目为angualr4

1.在HTML中加一个input,(不可display:none)

 ```

<input type="text" name="copyInput" id="copyInput" [(ngModel)]="copyvalue"
style="position: absolute;left:-100px;bottom:-100px">

```

2.js代码

```

import { ElementRef } from ‘@angular/core‘;
 
public copyvalue = ‘‘;
 
public toCopy(item) {
const input = this.el.nativeElement.querySelector(‘#copyInput‘);
this.copyvalue = item.url;
input.value = item.url;
input.select();
document.execCommand(‘Copy‘);
this._message.success(‘复制成功‘);
}
 
constructor(
private el: ElementRef
) {}

```

(getElementByClassName 无效)

点击复制指定内容

原文:https://www.cnblogs.com/zhuangcui/p/12132196.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!