<input type="text" id="text-box" size="20" value="Hello world!">
<button onclick="selectText()">Select text</button>複製代碼
function selectText() {
const input = document.getElementById('text-box');
input.focus();
input.select();
input.setSelectionRange(0, 5);
document.execCommand('copy');
}複製代碼
複製js庫git
命令文檔github