WordPress开发通过JS实现一键复制指定内容教程

在我们开发WordPress网站时有会需要通过JS实现一键复制指定内容,有脚本插件的还有就是这种简单纯脚本的,这里就不提供那种脚本插件的了,因为那种插件的代码太多,虽然功能要比较强大,但我们仅仅限于通过JS实现一键复制指定内容。

<div>
<span id="copyMy"> 复制我试试</span>
<button onClick="copyFn()">点击复制</button>
</div>
<script>
	function copyFn() {
		var val = document.getElementById('copyMy');
		window.getSelection().selectAllChildren(val);
		document.execCommand("Copy");
		alert("已复制好,可贴粘。");
 
	}
</script>

 

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
Warning: strpos() expects parameter 1 to be string, array given in /home/wwwroot/AMH_PHP7.4/domain/LULA_YMXZB/web/wp-content/themes/YMXZB/modules/common/Post.php on line 441 Warning: strpos() expects parameter 1 to be string, array given in /home/wwwroot/AMH_PHP7.4/domain/LULA_YMXZB/web/wp-content/themes/YMXZB/modules/common/Post.php on line 441
上一篇

wp_reset_postdata和wp_reset_query的作用与区别

2021-7-9 19:19:50

下一篇

WordPress调试查询耗时打印

2021-7-9 19:22:24