▽1
●
Cherenkov ●100ポイント ベストアンサー |
javascriptだけではクリップボードを使ってコピーペーストできません。
(flashを経由する方法もあります。最新のブラウザならいけるのかも)
以下のような考えでどうでしょうか。
http://jsfiddle.net/cherenkov/pH5wc/
<html> <head> <meta charset="utf-8"> </head> <body> <input type="button" id="btn" value="output"><br> <input type="text" name="1"><br> <input type="text" name="2"><br> <input type="text" name="3"><br> <textarea id="output"></textarea> <script> document.getElementById('btn').addEventListener('click', function() { document.getElementById('output').value = document.getElementsByName('1')[0].value +'\n'+ document.getElementsByName('2')[0].value +'\n'+ document.getElementsByName('3')[0].value; }, false); </script> </body> </html>
何の目的でコピペしたいのでしょうか?quocardさん個人で使いたいシステムでユーザースクリプト等を使ってもいいですか?(拡張ならコピペが可能)
入力フォームの内容をテキストボックスに出力することは可能ですが、
シチュエーションがわからないと適切な回答ができません。
-----------
上のは質問を正しく解釈していませんでした、失礼。
これでどうでしょう。選択文字列を取得するのに苦労するのでjQueryと以下のプラグインを使いました。
選択範囲のテキストを操作するjQueryプラグインjQuery.selection - 今日も適当ダイアリー
http://jsfiddle.net/cherenkov/pH5wc/2/
<html> <head> <meta charset="utf-8"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script> <script src="http://www.weekendphp.com/jQuery/jquery.selection-min.js" type="text/javascript"></script> <script> $(function() { $('#btn').click(function() { var selectText = $.getSelection('html').split('\n'); $('[name="1"],[name="2"],[name="3"]').each(function(i, e){ $(this).val(selectText[i]); }); }); }); </script> </head> <body> <pre> 1段目のコピー 2段目のコピー 3段目のコピー </pre> <input type="button" id="btn" value="output"><br> <input type="text" name="1"><br> <input type="text" name="2"><br> <input type="text" name="3"><br> </body> </html>