html部分

成縣網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián),成縣網(wǎng)站設(shè)計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為成縣上1000家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站建設(shè)公司要多少錢,請找那個售后服務(wù)好的成縣做網(wǎng)站的公司定做!
!DOCTYPE?html
html
head
titleZeroClipboard?Test/title
meta?charset="utf-8"
script?type="text/javascript"?src="clipboard.min.js"/script
script?type="text/javascript"?src="jquery-1.10.2.min.js"/script
/head
body
input?id="t"?type="text"/數(shù)據(jù)輸出測試br
textarea?id="t2"/textareabr
!--測試1--
!--button按鈕測試,需要復(fù)制的值放在屬性??data-clipboard-text中br--
button?class="btn"?data-clipboard-text="測試1"點(diǎn)擊測試1/buttonbrbr
!--測試2--
!--a按鈕測試,需要復(fù)制的值放在屬性?data-clipboard-text中br--
a?class="a"?data-clipboard-text="測試2"點(diǎn)擊測試2/abrbr
!--測試3--
!--測試,通過按鈕的data-clipboard-target屬性獲取指定標(biāo)簽中的值--
div測試3/div
button?class="btn2"?data-clipboard-action="copy"?data-clipboard-target="div"點(diǎn)擊測試3/buttonbrbr
!--測試4--
!--測試,通過按鈕的data-clipboard-target屬性獲取指id的標(biāo)簽中的值中?--
button?class="btn3"?data-clipboard-action="copy"?data-clipboard-target="#t2"點(diǎn)擊測試4/button
/body
/html
jquery部分:
!--測試1--
$(document).ready(function(){??
var?clipboard?=?new?Clipboard('.btn');?
clipboard.on('success',?function(e)?{
console.log(e);
alert("測試1復(fù)制成功!")
});
clipboard.on('error',?function(e)?{
console.log(e);
alert("測試1復(fù)制失敗!請手動復(fù)制")
});
})
!--測試2--
$(document).ready(function(){??
var?clipboard1?=?new?Clipboard('.a');?
clipboard1.on('success',?function(e)?{
console.log(e);
alert("測試2復(fù)制成功!")
});
clipboard1.on('error',?function(e)?{
console.log(e);
alert("測試2復(fù)制失敗!請手動復(fù)制")
});
})
!--測試3--
$(document).ready(function(){??
var?clipboard2?=?new?Clipboard('.btn2');?
clipboard2.on('success',?function(e)?{
console.log(e);
alert("測試3復(fù)制成功!")
});
clipboard2.on('error',?function(e)?{
console.log(e);
alert("測試3復(fù)制失敗!請手動復(fù)制")
});
})
!--測試4--
$(document).ready(function(){??
var?clipboard3?=?new?Clipboard('.btn3');?
clipboard3.on('success',?function(e)?{
console.log(e);
alert("測試4復(fù)制成功!")
});
clipboard3.on('error',?function(e)?{
console.log(e);
alert("測試4復(fù)制失敗!請手動復(fù)制")
});
})
注:此方法主要使用了clipboard,無需通過其他文件,引入一個clipboard.js文件即可使用,簡單方便
clipboard.js庫文件下載地址
出于安全問題,無法使用原生的 JS 或 jQuery 來操作粘貼板。除非使用瀏覽器擴(kuò)展(需設(shè)置權(quán)限),或者使用Flash。
某些瀏覽器允許在文本框內(nèi)使用 document.execCommand('copy') 與 document.execCommand('paste') 來操作剪貼板。
(但現(xiàn)在基于較新版本的webkit內(nèi)核以及主流的瀏覽器,該命令已經(jīng)被False)
如果你是想鼠標(biāo)選中后點(diǎn)擊復(fù)制到文本框內(nèi),其實(shí)不用剪貼板,可以獲取選中的內(nèi)容,然后在復(fù)制給文本框就可以了
網(wǎng)頁名稱:jquery剪切板,js調(diào)用剪切板
鏈接URL:http://chinadenli.net/article10/dsgeodo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供域名注冊、軟件開發(fā)、全網(wǎng)營銷推廣、小程序開發(fā)、網(wǎng)站維護(hù)、營銷型網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)