完整代码如下:
<html> <title>文本框内容全选与复制</title> <head> <style> .highlighttext{ background-color:yellow; font-weight:bold; } </style> </head> <form name=test> <input type="button" value="点此全选复制" onclick="javascript:HighlightAll('test.select1')" > <textarea name="select1" rows=3 cols=46 >脚本学堂,欢迎大家的光临!</textarea> </form> <script language="Javascript"> <!-- var copytoclip=1 function HighlightAll(theField) { var tempval=eval("document."+theField) tempval.focus() tempval.select() if (document.all && copytoclip==1){ therange=tempval.createTextRange() therange.execCommand("Copy") window.status="Contents highlighted and copied to clipboard!" setTimeout("window.status=''",1780) } } //--> </script> </head> </html>