Javascript implementation copy and paste operation instances

  • 2020-03-30 04:06:24
  • OfStack

This article illustrates how javascript implements copy and paste operations. Share with you for your reference.

The specific implementation method is as follows:

<script language="javascript"> 
function readTxt()
{
alert(window.clipboardData.getData("text"));
}
function setTxt()
{
var t=document.getElementById("txt");
t.select();
window.clipboardData.setData('text',t.createTextRange().text);
}
</script>
<input name="txt" value=" test ">
<input type="button" value=" copy " onclick="setTxt()">
<input type="button" value=" read " onclick="readTxt()">


Related articles: