<body>
<div id="view">
<img src="./Starbucks.jpg" alt="" style="width:200px;height:200px">
<input type="button" value="截图" onclick="takeScreenshot()">
</div>
<div id="box"></div>
<script>
function takeScreenshot() {
html2canvas(document.getElementById('view')).then(canvas => {
document.getElementById('box').appendChild(canvas)
});
}
</script>
</body>
展示:上边为元素,下边为点击后生成的图片