1. 程式人生 > >點選按鈕自動複製

點選按鈕自動複製

copyToClipboard: function() {
    var $temp = document.createElement("input");
    var val = window.location.href || "";
    document.body.appendChild($temp);
    $temp.value = val;
    $temp.select(); 
    $temp.setSelectionRange(0, val.length); //相容iphone safari
    try{
        document.execCommand("copy")
    }
    catch(err){}
    $temp.remove();
}