javascript实现复制功能

function  copyToClipboard(theField)
{
                     
var tempval=eval("document.all."+theField);
    tempval.focus();
    tempval.select();
                
    
if (document.all)
    
{
        therange
=tempval.createTextRange();
        therange.execCommand(
"Copy");
                    
        window.status
="Contents highlighted and copied to clipboard!"
        setTimeout(
"window.status=''",1800);
                    
        alert(
'成功复制到Windows剪贴板,现在可以直接粘贴到Email信纸。');
    }

}

说明:改方法的参数theField是页面中文本框或文本域的id。

你可能感兴趣的:(javascript实现复制功能)