使用js实现复制文字功能
function copyText() {
var text = $("#mobile").text();
var copy_input = window.document.getElementById("copy_input");
if (!copy_input) {
copy_input = window.document.createElement("input");
copy_input.id = "copy_input";
window.document.getElementsByTagName("BODY")[0].appendChild(copy_input);
}
copy_input.style.display = "block";
copy_input.value = text;
copy_input.select();
if (document.execCommand("copy"))
layer.msg("复制成功" + text);
copy_input.style.display = "none";
}
- 主要代码:
input.select();
document.execCommand(“copy”)