1.在页面中声明这个方法
//复制操作
function copyText(text) {
var textarea = document.createElement("textarea");
var currentFocus = document.activeElement;
document.body.appendChild(textarea);
textarea.value = text;
textarea.focus();
if (textarea.setSelectionRange)
textarea.setSelectionRange(0, textarea.value.length);
else
textarea.select();
try {
var flag = document.execCommand("copy");
} catch (eo) {
var flag = false;
}
document.body.removeChild(textarea);
currentFocus.focus();
return flag;
}
2.形参中传入要复制的值
var telNum = $("#telNum").val();
opyText(telNum);