移动端无法复制:使用clipboard.js碰到的一个小问题

移动端无法复制:使用clipboard.js碰到的一个小问题
 
直接看下面的代码:在移动端访问,点击,能正常复制。
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no, minimal-ui"/>
<body>

<div class="btn" style="cursor:pointer;">copy123456</div>

<script src="clipboard.min.js"></script>
<script src="jquery.min.js"></script>
<script>
    var clipboard = new Clipboard('.btn', {
        text: function () {
            return $(".btn").html();
        }
    });

    clipboard.on('success', function (e) {
        alert("复制成功");
    });

    clipboard.on('error', function (e) {
        alert("复制失败");
    });
</script>
</body>
</html>
View Code

 问题:把样式 cursor: pointer 去掉,在移动端点击没反应,复制不了(在PC端没这个问题)

( 如果上面不用 div,改用 button,那么这个问题不存在)

具体原因,没精力去探索了,先告诉那些可能遇到这个问题,却还没发现的朋友吧,别纠结了。

原文地址:https://www.cnblogs.com/liaolongjun/p/7753916.html