js外掛程式實現一鍵複製功能

2022-09-17 04:03:12 字數 781 閱讀 9283

clipboard.js 可以實現純 js 的從瀏覽器複製文字到系統剪貼簿的功能。

使用方法:

<

script

src="/lib/js/clipbaord.js"

>

script

>

2. 需要複製的目標文字

<

span

id="tar_text"

>我是一段需要被複製的文字

span

>

3. 複製按鈕(注:此處需要給觸發複製時間的按鈕新增兩個屬性,data-clipboard-action 及 data-clipboard-target,data-clipboard-target的屬性值為目標文字的 id 值)

<

button

id="copy"

data-clipboard-action

="copy"

data-clipboard-target

="#tar_text"

>copy my invitation address

button

>

4. 例項化 clipboard 物件

var clipboard = new clipboard('#copy');

clipboard.on('success', function (e) );

clipboard.on('error', function (e) );

js實現複製功能

在一些涉及到個人資訊比較多的h頁面,經常可能會出現複製賬號到剪下板的功能,那麼怎麼用js怎麼實現複製貼上功能呢?正好最近開發的模組中又有乙個這樣的功能,總結一下,方便後面使用。效果圖 核心 require clipboard function clipboard aftercopy function...

前端利用scss實現一鍵換膚功能

variables.scss 淺色主題 light theme base color 000,background color ccc 深色主題 dark theme base color fff,background color 000 定義對映集合 themes light theme ligh...

原生js實現複製功能

瀏覽器提供了 copy 命令 可以複製選中的內容 document.execcommand copy var text document.getelementbyid text innertext var input document.getelementbyid input input.value...