clipboard.js -- js實現將文本複製到剪貼板的方法

資源git

推薦使用:clipboard.jsgithub

官方教程地址:https://clipboardjs.com/#example-textspa

官方github地址:https://github.com/zenorocha/clipboard.js/code

 

基本用法解答blog

一、data-clipboard-target  在觸發器元素中添加屬性來實現教程

new ClipboardJS('.btn')

<input id="foo" value="我是被copy的值">

<button class="btn" data-clipboard-target="#foo"></button>

二、data-clipboard-action屬性以指定是要copy仍是cut內容
ip

new ClipboardJS('.btn')

<textarea id="bar">我是被copy或者cut的內容</textarea>

<button class="btn" data-clipboard-action="cut" data-clipboard-target="#bar"></button>

三、data-clipboard-text在觸發器元素中包含一個屬性資源

new ClipboardJS('.btn')

<button class="btn" data-clipboard-text="我是被copy的值"></button>

四、更多高級用法請參考官方文檔:https://clipboardjs.com/#example-text文檔

相關文章
相關標籤/搜索