複製到剪貼版
By @loverajoel
這是一個簡單的 tip,本週我建立了一個常見的「複製到剪貼版」按鈕,我以前不曾做過這樣的功能,我想分享我如何實作它。
它很簡單,比較麻煩的是我們必須加入一個 <input/>
與文字複製到 DOM。我們選擇內容並執行 execCommand 複製指令。
execCommand('copy')
將複製時間被選擇的內容
這個指令目前支援所有最新的瀏覽器,允許我們執行其他系統指令,像是:copy
、cut
、paste
和改變字體顏色、大小等等。
document.querySelector('#input').select();
document.execCommand('copy');
具體呈現請看參考這裡

Use the 100 answers in this short book to boost your confidence and skills to ace the interviews at your favorite companies like Twitter, Google and Netflix.
GET THE BOOK NOW

A short book with 100 answers designed to boost your knowledge and help you ace the technical interview within a few days.
GET THE BOOK NOW
Related tips
- Read More →
-
@loverajoel in javascriptRead More →
選擇或是拋棄物件屬性
有時候我們需要列出物件中某些屬性,假設我們有一個陣列來表達一個資料表,我們需要有些 function 來
select
欄位。 -
CasterBites: Farcaster Daily Digest
Dive into Farcaster's Daily Digest for your personalized must-reads. Spend just 3 minutes daily to stay updated with all things important. Never miss out again!