参照:Clipboard plugin for jQuery
「copy」クラスを持つ要素をクリックすると、その要素のtitle属性の値をクリップボードにコピーします。
a要素の内容をコピー span要素の内容をコピー
下記の要素をクリックすると、クリップボードに要素内のテキストがコピーされます。
クリックしたら、テキストエリアに[Ctrl]+[C]で貼り付けて確認できます。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="ja" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="imagetoolbar" content="no" />
<title>設置サンプル</title>
<link rel="stylesheet" type="text/css" href="/content/lib/global.css" />
<!-- JS -->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript" src="/content/lib/jquery/jquery.clipboard-2.0.1/jquery.clipboard.js"></script>
<script type="text/javascript">
$(function(){
$.clipboardReady(function(){
$(".copy").click(function(){
$.clipboard($(this).attr("title"));
return false;
});
},
{
swfpath: "/content/lib/jquery/jquery.clipboard-2.0.1/jquery.clipboard.swf",
debug:false
});
});
</script>
<!-- CSS -->
<style type="text/css">
.copy { border:1px solid #ff6699; padding:3px 5px; margin:0 10px; color:#ff6699; cursor:pointer; }
.copy:hover { background:#ff6699; color:#fff; }
</style>
<link rel="stylesheet" type="text/css" href="/common/css/example.css"></head>
<body id='example3' class='example'><div class="ads" style="margin:32px auto;text-align:center;"></div><h1 class='h'><a href='/'>PHP & JavaScript Room</a> :: 設置サンプル</h1>
<h3 class='h'>実行結果</h3>
<body id='example3' class='example'><div class="ads" style="margin:32px auto;text-align:center;"></div><h1 class='h'><a href='/'>PHP & JavaScript Room</a> :: 設置サンプル</h1>
<h3 class='h'>実行結果</h3>
<h1>設置サンプル</h1>
<p>参照:<a href='http://bradleysepos.com/projects/jquery/clipboard/' target='_blank'>Clipboard plugin for jQuery</a></p>
<!-- CODE -->
<p>「copy」クラスを持つ要素をクリックすると、その要素のtitle属性の値をクリップボードにコピーします。</p>
<p>
<a href="#" class="copy" title="A要素をクリックしましたね">a要素の内容をコピー</a>
<span class="copy" title="SPAN要素をクリックしましたね">span要素の内容をコピー</span>
</p>
<p>
下記の要素をクリックすると、クリップボードに要素内のテキストがコピーされます。<br>
クリックしたら、テキストエリアに[Ctrl]+[C]で貼り付けて確認できます。
</p>
<p><textarea id="paste_area" cols="50" rows="6"></textarea></p>
<!-- / CODE -->
</body>
</html>