本文目錄一覽:
web前端怎麼實現點擊按鈕複製鏈接
script type=”text/javascript”
function copyUrl() {
var Url = document.getElementById(“url1”);
Url.select(); // 選擇對象
document.execCommand(“Copy”); // 執行瀏覽器複製命令
alert(“已複製好,可貼粘。”);
}
/script
input type=”text” value=”” id=”url1″ /
input type=”button” onClick=”copyUrl()” value=”點擊複製代碼” /
js 如何實現將div內的內容放到剪切板?
定義如下JS函數,然後DIV觸發onclick 事件就OK。
function CopyUrl()
{
var htm = document.getElementById(“yourdiv”).innerHTML;
window.clipboardData.setData(‘text’, htm);
}
yourdiv 就是你的div的ID
JS如何實現修改複製內容?比如我複製了abc但是粘貼出來的是efg。
可以寫一個點擊件事和隱藏域 我是採用的jquery
script type=”text/javascript”
function copyUrl2()
{
var Url2=document.getElementById(“biao1”);
Url2.select(); // 選擇對象
document.execCommand(“Copy”); // 執行瀏覽器複製命令
alert(“已複製好,可貼粘。”);
}
/script
div class=”fenxian_link fixed”
span onClick=”copyUrl2()”複製邀請鏈接/span
textarea cols=”90″ rows=”1″ abc/textarea
input type=’hidden’ id=’biao1′ value=’efg’/
/div
原創文章,作者:XURA,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/132037.html