1

仕事のドキュメント用の楽しいスクリプトを作成しようとしています。これが私がこれまでに持っているものです。

<script type="text/javascript">
    function ClipBoard() {
        window.clipboardData.setData('text',
                      document.getElementById('name').value +
                      document.getElementById('phone').value +
                      document.getElementById('serial').value +
                      document.getElementById('new').value +
                      document.getElementById('cuts').value +
                      document.getElementById('agts').value
                     );
    }

</script>
<form id="form1">
    Name: <input id="name" /><br />
    Phone Number: <input id="phone" maxlength="10" /><br />
    Serial Number: <input id="serial" maxlength="10" /><br />
    New/Existing: <input id="new" /><br />
    CU TS: <input id="cuts" /><br />
    Agent TS: <input id="agts" /><br />
    <input type="button" onclick="ClipBoard()" value="Copy"/>
    <input type="reset" />`

入力を貼り付けた後、代わりに「ブレーク」がなく、コピーされたテキストが行にコピーされます。例:namephoneserialnew など お願いします: Name Phone Serial New Etc. 改行あり。

できれば。

また、入力をコピーするときに、入力の前にテキストをコピーする方法はありますか。例:名前:(入力あり)、電話番号:(入力あり)など

どんな提案でも非常に役に立ちます。これは基本的なスクリプトであり、深刻なことではありません。みんなありがとう!

4

2 に答える 2

1

ctl 値の後に「\r\n」を追加してみてください。

function ClipBoard() {
    window.clipboardData.setData('text',
                  document.getElementById('name').value + '\r\n' + 
                  document.getElementById('phone').value + '\r\n' + 
                  document.getElementById('serial').value + '\r\n' + 
                  document.getElementById('new').value + '\r\n' + 
                  document.getElementById('cuts').value + '\r\n' + 
                  document.getElementById('agts').value
                 );
}
于 2014-06-09T07:04:14.550 に答える
0

JavaScript は、このように改行を生成しません。コードを追加"<br>"してみると、改行が表示される場合があります。

function ClipBoard() {
        window.clipboardData.setData('text',
                      document.getElementById('name').value + "<br>"
                      document.getElementById('phone').value + "<br>" 
                      document.getElementById('serial').value + "<br>"
                      document.getElementById('new').value + "<br>"
                      document.getElementById('cuts').value + "<br>"
                      document.getElementById('agts').value
                     );
    }

値の前にラベルが必要な場合は、それらの前に文字列を配置できます。

function ClipBoard() {
            window.clipboardData.setData('text',
                          "Name: " + document.getElementById('name').value + "<br>"
                          "Phone: " + document.getElementById('phone').value + "<br>" 
                          "Serial: " + document.getElementById('serial').value + "<br>"
                          "New: " + document.getElementById('new').value + "<br>"
                          "Cuts: " + document.getElementById('cuts').value + "<br>"
                          "Agts: " + document.getElementById('agts').value
                         );
        }

ところで、HTML の終了タグを忘れました。

于 2012-11-08T05:25:36.880 に答える