我正在尝试将pre标签内写的代码复制到剪贴板中.我怎样才能做到这一点?我试图使用下面的代码解决这个问题:
function myFunction() {
var copyText = document.getElementById("myInput");
copyText.select();
document.execCommand("Copy");
alert("Copied the text: " + copyText.value);
}Run Code Online (Sandbox Code Playgroud)
<pre id="myInput">
<span style="color:#97EDDC;">class </span>first
{
<span style="color:#97EDDC;">public</span> <span style="color:#97EDDC;">static </span> <span style="color:#97EDDC;">void </span> main(String args[]) // here S is capital of String word
{
System.out.println("Hello World!!"); // here S is capital of System word
}
}
</pre>Run Code Online (Sandbox Code Playgroud)
给我一个正确的解决方案,将代码从pre标签复制到剪贴板,而不包括span标签.