<div style="text-indent: 2em;">
原理:先选中控件中的内容(如文本),再执行文档对象的复制命令。
代码:
function copyIt(o) { try { if (o.value.length > 0 ) { o.select(); window.document.execCommand('Copy'); alert('复制成功'); } } catch (oError) { alert(oError); } }
<div style="text-indent: 2em;">
原理:先选中控件中的内容(如文本),再执行文档对象的复制命令。
代码:
function copyIt(o) { try { if (o.value.length > 0 ) { o.select(); window.document.execCommand('Copy'); alert('复制成功'); } } catch (oError) { alert(oError); } }