<textarea rows="10" cols="20" onmouseover="select();document.execCommand('copy')">
测试
</textarea>

解决方案 »

  1.   

    如何选择文本框内容并粘贴到剪切板上
    <style>
    .highlighttext{
    background-color:yellow;
    font-weight:bold;
    }
    </style><script language="Javascript">
    <!--//选择文本框的内容是否需要自动复制到剪切板上
    //Applies only to IE 4+
    //0=no, 1=yes
    var copytoclip=1function HighlightAll(theField) {
    var tempval=eval("document."+theField)
    tempval.focus()
    tempval.select()
    if (document.all&&copytoclip==1){
    therange=tempval.createTextRange()
    therange.execCommand("Copy")
    window.status="选择文本框内容并复制到剪切板上"
    setTimeout("window.status=''",1800)
    }
    }
    //-->
    </script><body>
    <form name="test">
    <a class="highlighttext" href="javascript:HighlightAll('test.select1')">
    选择并粘贴</a><br>
    <textarea name="select1" rows=10 cols=35 >这里是文本框的具体内容</textarea>
    </form>
    </body>
      

  2.   

    <textarea id=demo>abcdef</textarea> 
    <input type=button onclick=addText2(demo,"1234") value="AddText"> 
    <script> 
    function addText2(oTextarea,strText){ 
    //strText是你要加入剪切板的内容.
    clipboardData.setData("text",strText); 
    oTextarea.focus(); 
    document.execCommand("paste"); 

    </script>