亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何復制我的網頁中顯示的帶有嵌入按鈕的代碼

如何復制我的網頁中顯示的帶有嵌入按鈕的代碼

慕田峪7331174 2021-06-11 18:09:20
function copy() {    var x= document.getElementById("content");    x.select();    document.execCommand('copy');      window.getSelection().removeAllRanges();}這是我用來選擇和復制輸入內容的js代碼。如果我想在我的網頁上添加一個按鈕來選擇一些 div 并將顯示的代碼復制到剪貼板中,該怎么辦。
查看完整描述

2 回答

?
暮色呼如

TA貢獻1853條經驗 獲得超9個贊

在這里,我想出了我自己問題的解決方案。

網址:


<div id="divid" onclick="copy('divid')">Division to be copied</div> 

js:


function copy(i)

        {

         var range = document.createRange();

        range.selectNode(document.getElementById(i));

        window.getSelection().removeAllRanges();

        window.getSelection().addRange(range); 

        document.execCommand('copy');

}


查看完整回答
反對 回復 2021-06-24
  • 2 回答
  • 0 關注
  • 208 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號