js復(fù)制到剪貼板(只支持ie)
<!DOCTYPE?html>
<html?lang="en">
<head>
????<meta?charset="UTF-8">
????<meta?http-equiv="X-UA-Compatible"?content="IE=edge">
????<meta?name="viewport"?content="width=device-width,?initial-scale=1.0">
????<title>Document</title>
</head>
<body>
????
????<script?type="text/javascript">
????????function?copyText(obj)?{?
????????var?rng?=?document.body.createTextRange();?
????????rng.moveToElementText(obj);?
????????rng.scrollIntoView();?
????????rng.select();?
????????rng.execCommand("Copy");?
????????rng.collapse(false);?
????????alert("復(fù)制成功!");?
????????}?
????????function?oCopy(id){
????????????var?obj=document.getElementById(id);
????????????obj.select();
?????????????js=obj.createTextRange();
?????????????js.execCommand("Copy");
?????????????alert("代碼已經(jīng)被成功復(fù)制!");
????????}
????????</script>
????????
????????//以下是代碼片段:
????????<span?id="tbid">http://pmp.www.jb51.net</span>???
????????<a?href="#"?onclick="copyText(document.all.tbid)">點(diǎn)擊復(fù)制</a>
????????<span?id="tbid2">http://www.www.jb51.net/pmp</span>???
????????<a?href="#"?onclick="oCopy(tbid2)">點(diǎn)擊復(fù)制</a>
????
</body>
</html>