簡體   English   中英

無法從剪貼板復制文本

[英]Cannot copy text from clipboard

我想在現有網頁上添加一個按鈕,將文本復制到 Windows 剪貼板。

所以現在我想添加一個 Javascript function 和一個調用 function 的 HTML 按鈕,將 output 復制到 Windows 剪貼板。

問題:按下按鈕時沒有復制任何內容

 <section class="content-header"> <div class="container-fluid"> <div class="row mb-2"> <div class="col-md-6"> <h1>Nomor Peminjaman: <button onclick="copyText()">00747-SKS/OS/12/2022</button> <input type="text" value="00747-SKS/OS/12/2022" id="textNya" hidden> </h1> </div> </div> </div> </section> <script> function copyText() { var copyText = document.getElementById("textNya"); copyText.select(); navigator.clipboard.writeText(copyText.value); } </script>

 function copyText() { var copyText = document.getElementById("textNya"); copyText.select(); navigator.clipboard.writeText(copyText.value); }
 <h1>Nomor Peminjaman:</h1> <input type="text" value="aabcdef" id="textNya" hidden> <button onclick="copyText()">Copy</button>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM