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 ...
随机推荐
- Docker Error response from daemon: driver failed programming external connectivity on endpoint webserver
按照官网的配置, https://docs.docker.com/docker-for-windows/ 当执行到第 5 步时 如果当前你的电脑 80 端口已经被别的程序占用,运行以上命令就会报错,报 ...
- [转]WebMercator与经纬度互转
//经纬度转Web墨卡托 Vector3 lonLat2WebMercator(Vector3 lonLat) { Vector3 mercator; ; + lonLat.y)*)) / (); y ...
- ModSecurity:一款优秀的开源WAF
一.ModSecurity3.0介绍 ModSecurity是一个开源的跨平台Web应用程序防火墙(WAF)引擎,用于Apache,IIS和Nginx,由Trustwave的SpiderLabs开发. ...
- python中的修饰符@的作用
1.一层修饰符 1)简单版,编译即实现 在一个函数上面添加修饰符 @另一个函数名 的作用是将这个修饰符下面的函数作为该修饰符函数的参数传入,作用可以有比如你想要在函数前面添加记录时间的代码,这样每个函 ...
- linux安装上传下载工具lrszs
普通用户下使用sudo获取root权限,root用户直接安装: [mall@VM_0_7_centos ~]$ sudo yum -y install lrzsz Loaded plugins: fa ...
- jenkins下载插件Git Parameter插件
登陆jekinse -> 点击左边菜单列表 -> 点”系统管理“ -> 下拉点”插件管理“ -> 选“可选插件”,在右上角过滤框输入”Git Parameter” -> ...
- Linux记录-mysql服务管理shell实现
#!/bin/bash menu() { echo "---欢迎使用mysql管理服务程序---" echo "# 1.启动服务" echo "# 2 ...
- 123457123456#0#----com.DoraGame.YingYu65--前拼后广--儿童英语doraX
com.DoraGame.YingYu65--前拼后广--儿童英语doraX
- 123457123457#0#-----com.tym.YuErBaiKeTYM--前拼后广--育儿百科
com.tym.YuErBaiKeTYM--前拼后广--育儿百科
- iOS电商类App研发学习总结
一.涵盖知识点: 1.电商类App架构: https://www.cnblogs.com/loying/p/4801194.html 2.快速搭建电商平台: https://www.jianshu.c ...