1.js复制<textarea>标签文字
<textarea cols="40" rows="5" id="textareaValue">我是textarea标签</textarea> </br>
function copyTextareaValue() { var textareaValue = document.getElementById("textareaValue"); textareaValue.select(); // 选择对象 document.execCommand("Copy"); alert("已复制好,可贴粘。"); }
2.js复制<input>标签文字
<input id="inputValue" value="我是input标签"/></br>
function copyInputValue() { var inputValue = document.getElementById("inputValue"); inputValue.select(); // 选择对象 document.execCommand("Copy"); alert("已复制好,可贴粘。"); }
3.js复制<span>标签文字
<span id="spanValue">我是span标签</span></br>
function copySpanValue() { var spanValue = document.getElementById('spanValue'); window.getSelection().selectAllChildren(spanValue); document.execCommand("Copy"); alert("已复制好,可贴粘。"); }
demo下载地址:https://download.csdn.net/download/qq_28759359/10490807