Created
August 19, 2017 02:39
-
-
Save sunshare/4f9afd5c18361c17b831c0e0123fecfa to your computer and use it in GitHub Desktop.
Javascript copy string to clipboard.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<meta charset="UTF-8" /> | |
<title>Welcome</title> | |
<!--<script src="https://cdn.bootcss.com/clipboard.js/1.7.1/clipboard.min.js"></script>--> | |
</head> | |
<body> | |
<div> | |
<input id="copyipt" type="text" name="copyipt" readonly value="mmcy"> | |
<!--<button id="copy1" data-clipboard-target="#copyipt">点击复制左侧内容</button>--> | |
<p id="copy1">点击复制左侧内容</p> | |
</div> | |
<script type="text/javascript"> | |
var el = document.getElementById("copyipt"); | |
var btn = document.getElementById("copy1"); | |
//var clip = new Clipboard('#copy1'); | |
btn.onclick = function (e) { | |
console.log("btn click"); | |
e.preventDefault(); | |
el.select(); | |
console.log(document.execCommand("copy")); | |
} | |
window.onload = function () { | |
console.log("hello"); | |
btn.click(); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment