其他分享
首页 > 其他分享> > jQuery复制到剪贴板clipboard.js简单用法

jQuery复制到剪贴板clipboard.js简单用法

作者:互联网

复制到剪贴板

<!-- 引入js文件 -->
<script src="https://cdn.bootcdn.net/ajax/libs/clipboard.js/2.0.8/clipboard.min.js"></script>

<!-- 给dom添加class/data-clipboard-text属性 -->
<div class="copy" data-clipboard-text="${d.f_id}" >${d.f_id}</div>

<!-- 创建Clipboard对象并监听 -->
<script>
var clipboard = new ClipboardJS('.copy')
clipboard.on('success', function (e) {
	layer.msg('已复制:' + e.text, { icon: 9, time: 1000 })
})
</script>

复制文本框里的内容

<div class="layui-input-inline">
	<input name="zsws_name" id="zsws_name" value="{$row['zsws_name']}" class="layui-input" placeholder="请输入单位名称" />
</div>
<div class="layui-inline">
	<button class="copy" data-clipboard-action="copy" data-clipboard-target="#zsws_name">复制</button>
	<script src="/Public/js/clipboard.min.js"></script>
	<script>
		let clipboard = new ClipboardJS('.copy')
		clipboard.on('success', function (e) {
			console.log(e)
			e.clearSelection()
		})
	</script>
</div>

标签:jQuery,复制到,剪贴板,function,clipboard,ClipboardJS,new,copy
来源: https://www.cnblogs.com/sunr/p/16670211.html