vue复制textarea文本域内容到粘贴板
- <template>
- <div>
- <textarea ref="letters"></textarea>
- <button @click="copyToClipboard('letters')">复制</button>
- </div>
- </template>
- <script>
- export default {
- data() {
- return {
- loading: false
- }
- },
- created() {
- this.$nextTick(function () {
- this.$refs.letters.value = '用户名:张三\n性别:男\n电话号码:15812322222';
- })
- },
- methods: {
- //复制内容到粘贴板
- copyToClipboard(elemRef) {
- let target;
- let succeed = false;
- if(this.$refs[elemRef]){
- target = this.$refs[elemRef];
- // 选择内容
- let currentFocus = document.activeElement;
- target.focus();
- target.setSelectionRange(0, target.value.length);
- // 复制内容
- try {
- succeed = document.execCommand("copy");
- alert("内容复制成功");
- } catch (e) {
- succeed = false;
- }
- // 恢复焦点
- if (currentFocus && typeof currentFocus.focus === "function") {
- currentFocus.focus();
- }
- }
- return succeed;
- },
- }
- }
- </script>
vue复制textarea文本域内容到粘贴板的更多相关文章
- textarea文本域的高度随内容的变化而变化
用css控制textarea文本域的高度随内容的变化而变化,不出现滚动条. CSS代码: 复制代码 代码如下: .t_area{ width:300px; overflow-y:visible } & ...
- div模拟textarea文本域轻松实现高度自适应——张鑫旭
by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.com/wordpress/?p=1362 一.关于tex ...
- 使用contenteditable+div模拟textarea文本域实现高度自适应
使用contenteditable+div模拟textarea文本域实现高度自适应 开发过程中由于需要在发送消息的时候需要有一个可以高度自适应的文本域,一开始是使用textarea并搭配auto-si ...
- Kindeditor富文本实现textarea文本域的上传及单独button 按钮绑定(用来实现单文件上传)
在最近项目要新增一个内容文章,文章包含一般的正文内容,其中正文中可以包含多张图片.文章最多包含一个音频文件.文章正文的上传功能我是通过textarea文本域绑定kindeditor编辑器实现的,而单独 ...
- js插件实现点击复制内容到粘贴板,兼容IE8
先来看下本次需要导入的文件: 第一个是jquery.js,这个不多说: 第二个是jquery.zclip.js,第三个是zeroClipboard.swf ,这两个文件的下载链接:http://www ...
- js点击按钮复制内容到粘贴板
复制内容到粘贴板,就是要选择需要复制的内容并执行document.execCommand("copy")命令: //复制内容到粘贴板 function copyToClipboar ...
- textarea文本域轻松实现高度自适应
转载:http://www.xuanfengge.com/textarea-on-how-to-achieve-a-high-degree-of-adaptive.html 今天需要些一个回复评论的页 ...
- css之——div模拟textarea文本域的实现
1.问题的出现: <textarea>标签为表单元素,但一般用于多行文本的输入,但是有一个明显的缺点就是不能实现高度自适应,内容过多就回出现滚动条. 为了实现高度自适应:用div标签来代模 ...
- div模拟textarea文本域轻松实现高度自适应
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
随机推荐
- Dart静态方法、对象操作符和类的继承
/* Dart中的静态成员: 1.使用static 关键字来实现类级别的变量和函数 2.静态方法不能访问非静态成员,非静态方法可以访问静态成员 */ // class Person { // stat ...
- openresty开发系列18--lua的字符串string操作
openresty开发系列18--lua的字符串string操作 string的相关操作 1)string.upper(s)接收一个字符串 s,返回一个把所有小写字母变成大写字母的字符串.print( ...
- 实战c++中的string系列--std:vector 和std:string相互转换(vector to stringstream)
string.vector 互转 string 转 vector vector vcBuf;string stBuf("Hello DaMao!!!");----- ...
- C++ STL排序问题
/* stl排序 */ #include <iostream> #include <map> #include <vector> #include <list ...
- 简单明了的注解,读取CLASS中的注解
/***********注解声明***************/ /** * 水果名称注解 * @author peida * */ @Target(ElementType.FIELD) @Reten ...
- Docker:学习笔记(1)——基础概念
Docker:学习笔记(1)——基础概念 Docker是什么 软件开发后,我们需要在测试电脑.客户电脑.服务器安装运行,用户计算机的环境各不相同,所以需要进行各自的环境配置,耗时耗力.为了解决这个问题 ...
- Python:实现图片裁剪的两种方式——Pillow和OpenCV
原文:https://blog.csdn.net/hfutdog/article/details/82351549 在这篇文章里我们聊一下Python实现图片裁剪的两种方式,一种利用了Pillow,还 ...
- 客户端连接Codis集群
新建maven webapp项目 添加相关依赖: <dependency> <groupId>redis.clients</groupId> <artifac ...
- SCI-hub使用技巧(下载外文文献)
下载外文文献方法指南: (1)首先查找需要下载文献的DOI (2)在Sci-Hub主页搜索框输入URL.DOI或者PMID. (3)点击open即可看见下载界面. 参考文献:https://mp.we ...
- [转帖]HAProxy 7层 负载均衡
HAProxy 7层 负载均衡 https://www.cnblogs.com/jicki/p/5546902.html HAProxy 系统 CentOS 5.8 x64 wget http://h ...