Skip to content

Instantly share code, notes, and snippets.

@pon-x
Last active November 6, 2020 01:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pon-x/68cb32488ff00be4da77bc608520ae07 to your computer and use it in GitHub Desktop.
Save pon-x/68cb32488ff00be4da77bc608520ae07 to your computer and use it in GitHub Desktop.
コピペボタンを実装する
<html>
<body>
<input id="copy1" type="text" value="target1" readonly>
<button onclick="CopyClip(1)">コピー</button>
<p>
<input id="copy2" type="text" value="target2" readonly>
<button onclick="CopyClip(2)">コピー</button>
<script>
function CopyClip(id) {
var target = document.getElementById('copy' + id);
target.select();
document.execCommand("Copy");
alert("文字列「 " + target.value + "」をコピーしました。");
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment