Home >Web Front-end >JS Tutorial >Use of javascript copy and paste and clipboardData_javascript skills

Use of javascript copy and paste and clipboardData_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:33:451495browse

window.clipboardData can realize copy and paste operations, its getData method can realize data reading, and the setData method can realize data setting

 <script language="javascript"> 
function readTxt() 
{ 
alert(window.clipboardData.getData("text")); 
} 
function setTxt() 
{ 
var t=document.getElementById("txt"); 
t.select(); 
window.clipboardData.setData('text',t.createTextRange().text); 
} 
</script> 
<input name="txt" value="测试"> 
<input type="button" value="复制" onclick="setTxt()"> 
<input type="button" value="读取" onclick="readTxt()">
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn