許多的部落格平台為了方便使用者或管理者複製文章的內容 ,因此都會提供 Copy Button  的功能

讓使用者不用再手動按 "複製" 就能將指定的文字區域的文字內容 複製到 剪貼簿 暫存

要達成這樣的需求 ,可以在下面這段 JavaScript 函式去達成它.

<script type="text/javascript">
function cmdA(el) {
with(el){
focus();
select();
}
if(document.all){
txt=el.createTextRange()
txt.execCommand("Copy")
window.status='Selected and Copied to Clipboard!'
document.WordForm.cpyButton.value="Copied!";
setTimeout("WordForm.cpyButton.value='Copy'",1000)
}
else window.status='Press Ctrl-C to Copy the Text to the Clipboard'
setTimeout("window.status='WebTv users you must Press Cmd & C !'",3000)
}
</script>


<form name="WordForm" >
<input type="text" id="Editbox1" size="30" name="Screen" value="This text should be copied">
<input type="button" width="120" NAME="cpyButton" value="Copy" onClick="cmdA(document.WordForm.Screen)">

以上請參考 .如有問題 歡迎透過留言版發問 ,謝謝.


arrow
arrow
    全站熱搜

    Frank 發表在 痞客邦 留言(0) 人氣()