【发布时间】:2021-01-25 22:59:27
【问题描述】:
我承认我对 Javascript 并没有任何了解。我在互联网上找到了这个,它确实可以满足我的要求:
<script type="text/javascript">
function CopyToClipboard(containerid) {
if (document.selection) {
var range = document.body.createTextRange();
range.moveToElementText(document.getElementById(containerid));
range.select().createTextRange();
document.execCommand("copy");
} else if (window.getSelection) {
var range = document.createRange();
range.selectNode(document.getElementById(containerid));
window.getSelection().addRange(range);
document.execCommand("copy");
alert("The assignment slip has been copied, now paste into an email")
}
}
</script>
它是这样称呼的:
<button id="button1" onclick="CopyToClipboard('containter-student-slip1')">Click to copy</button>
问题是我必须在单击浏览器中的下一步按钮之前清除选择。我希望它只需选择带有 ID 的指定元素并替换浏览器中的任何存在选择。
【问题讨论】:
标签: javascript