在canvas中我用红色填充背景并写上了文字请清除文字不要清除背景给出html代码
<!DOCTYPE html>
<html>
<head>
<title>Clear Text on Canvas</title>
</head>
<body>
<canvas id="myCanvas" width="400" height="200" style="background-color: red;"></canvas>
<script>
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
ctx.font = "30px Arial";
ctx.fillStyle = "white";
ctx.fillText("Hello World", 50, 50);
// Clear text
ctx.fillStyle = "red";
ctx.fillRect(50, 30, 200, 50);
</script>
</body>
</html>
原文地址: http://www.cveoy.top/t/topic/h6ZV 著作权归作者所有。请勿转载和采集!