在最近一个WordPress主题定制开发项目中,需要实现点击文字后自动复制文字(也就是微信号),同时在移动端自动打开微信APP方便添加该微信号为自己的好友,于是就到网上搜了一下,还真有简单好用的方法,现在给大家分享一下,希望对有同样需求的朋友能有所帮助。
一、html部分
在你需要显示微信号文字(也可以是按钮形式等)的地方使用下面的代码:
<span id="target" style="display: none;">微信号</span>
<a href="javascript:;" data-clipboard-target="#target" id="copy_btn">
<span>加店长微信</span>
</a>
二、js部分
<script src="https://cdn.jsdelivr.net/clipboard.js/1.5.12/clipboard.min.js"></script>
<script>
$(document).ready(function(){
var clipboard = new Clipboard('#copy_btn');
clipboard.on('success', function(e) {
alert("微信号复制成功",1500);
window.location.href='weixin://';
e.clearSelection();
console.log(e.clearSelection);
});
});
</script>
以上就是实现如题所说的效果的方法,亲测有效,希望可以帮助到您。
Related: how to hang wreath on range hood, are lake and michelle from amazing race still together, great eared nightjar pet for sale, laura velasquez wedding, arbitration and award affirmative defense, traci williams sharp, winston and aly relationship timeline, mccormick rosemary chicken recipe, hypnotherapy certification california, lisa thibault florida, wild horse pass raceway closing, how much did kevin hart make on irresponsible tour, effects of mandinka resistance, what football team does mark wright support, hicks funeral home obituaries macon, ga,
还没有任何评论,你来说两句吧