js复制文案-移动端可用

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>test</title>
</head>
<body>
<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");

}
</script>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/qq_27064559/article/details/84023822
今日推荐