使用JavaScript复制网页控件中的内容

原理:先选中控件中的内容(如文本),再执行文档对象的复制命令。

代码:

function copyIt(o) {
  try {
    if (o.value.length > 0 ) {
      o.select();
      window.document.execCommand('Copy');
      alert('复制成功');
    }
  } catch (oError) {
    alert(oError);
  }
}

现在就来练习使用它!

Add comment

Loading