<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<input type="text" id="inputbox" style="width:400px;"/>
<br /><br />
<input type="button" onclick="copyToInputBox()" value="从粘贴板拷贝"/>
<input type="button" onclick="clearText()" value="清除"/>
<br /><br />
<a id="capText">————————————————————</a>
<script>
function clearText(){
document.getElementById('inputbox').value=''
document.getElementById('capText').innerText='————————————————————'
}
function copyToInputBox(){
navigator.clipboard.readText().then(text => {
var input = document.getElementById('inputbox').value=text;
})
.catch(err => {
console.error('Failed to read clipboard contents: ', err);
});
};
document.addEventListener('paste', function (evt) {
var pastext=evt.clipboardData.getData('text/plain')
document.getElementById('capText').innerText=pastext
});
</script>
</body>
</html>