<script type="text/javascript">
//复制
function copytxt() {
alert("进入该函数。");
var txt = "";
if (window.getSelection) {
txt = window.getSelection();
}
else if (document.getSelection) {
txt = document.getSelection();
}
else if (document.selection) {
txt = document.selection.createRange().text;
}
copyToClipboard(txt);
}
//粘贴
function pastetxt() {
var ta = document.getElementById("selectedtext");
ta.focus();
ta.document.execCommand("paste"); // 粘贴
}
//复制到粘贴板函数
function copyToClipboard(txt) {
if (window.clipboardData) {
window.clipboardData.clearData();
window.clipboardData.setData("Text", txt);
}
}
</script>
js复制
最新推荐文章于 2024-09-01 17:43:51 发布