Generate a picture through html2canvas, and find that the checkbox selected item does not take a screenshot successfully.
<!DOCTYPE html>
<html>
<head>
<title>
html2canvas
</title>
</head>
<body id="myPage" onload="createImage()">
<p style="height: 100px;width: 100px;background-color: blue">
我是p
性别:
<input type="checkbox" name="sex">男
<input type="checkbox" name="sex">女
</p>
</body>
<script type="text/javascript" src="html2canvas.js"></script>
<script type="text/javascript">
function createImage(){
html2canvas(document.getElementById('myPage'),{
allowTaint:true,
height: 500
}).then(function(canvas) {
console.log(canvas);
var aTag = document.createElement("a");
aTag.innerHTML = "This is a test";
aTag.setAttribute("style", "position:absolute; top:50%; z-index:999");
aTag.setAttribute("href", canvas.toDataURL());
aTag.setAttribute("download", "myPic.png");
document.body.appendChild(aTag);
});
}
</script>
</html>
Page and production pictures:
It can be used, because the image is generated as soon as you enter the page, and subsequent clicks will have no effect, so you can do it this way.