function copyStr(val) { //val 是要复制的字符串 var input = document.createElement("input"); input.value = val; input.readOnly = true document.body.appendChild(input); input.select(); input.setSelectionRange(0, input.value.length) document.execCommand(‘Copy‘); document.body.removeChild(input); window.scrollTo(0, 0) alert(‘复制成功‘) }