<button onclick="copyToClip('內容')"> Copy </button>
/** * 復制內容到粘貼板 * content : 需要復制的內容 * message : 復制完后的提示,不傳則默認提示"復制成功" */ function copyToClip(content, message) { var aux = document.createElement("input"); aux.setAttribute("value", content); document.body.appendChild(aux); aux.select(); document.execCommand("copy"); document.body.removeChild(aux); if (message == null) { alert("復制成功"); } else{ alert(message); } }