createTextRange Sample

<html>
<head>

<script language="Javascript" type="text/javascript">
function sixteenth(src)
{
    var oSrc = eval("document." + src);
    oSrc.focus();
    oSrc.select();

    textRange = oSrc.createTextRange();
    textRange.execCommand("Copy");
    window.status = "Text is copied to clipboard!";
    setTimeout("window.status=''", 1000);

}
</script>

</head>

<body>

<form name="text">
<a href="javascript:sixteenth('text.code')"> &nbsp;Copy All&nbsp; </a><br><br>
<textarea name="code" rows=10 cols=35 >1st JavaScript Editor is used to create animations and other special effects for Web pages using DHTML and JavaScript.
</textarea>
</form>

</body>
</html>

原文地址:https://www.cnblogs.com/helife/p/1920815.html